TeeChartPHP
[ class tree: TeeChartPHP ] [ index: TeeChartPHP ] [ all elements ]

Source for file GraphicsGD.php

Documentation is available at GraphicsGD.php

  1. <?php
  2.  
  3. /**
  4.  * GraphicsGD class
  5.  *
  6.  * Description: Class with all Chart drawing methods.
  7.  *
  8.  * @author
  9.  * @copyright (c) 1995-2010 by Steema Software SL. All Rights Reserved. <info@steema.com>
  10.  * @version 1.0
  11.  * @package TeeChartPHP
  12.  * @subpackage
  13.  * @link http://www.steema.com
  14.  */
  15.  
  16. class GraphicsGD extends TeeBase
  17. {
  18.     // Private properties
  19.     private $tmpImg=null;
  20.     private $rectClip;
  21.     private $polygonClip;
  22.     private $is3D=false;
  23.     private $isOrtho=false;
  24.     private $iZoomText=false;
  25.     private $xCenter=0;
  26.     private $yCenter=0;
  27.     private $zCenter=0;
  28.     private $xCenterOffset=0;
  29.     private $yCenterOffset=0;
  30.     private $buffered=true;
  31.     private $rotationCenter=null;
  32.     protected $moveToX;
  33.     protected $moveToY;
  34.     private $iPoints;
  35.     private $s2;
  36.     private $c1;
  37.     private $s1;
  38.     private $c3;
  39.     private $s3;
  40.     private $c2;
  41.     private $c2s3;
  42.     private $c2c3;
  43.     private $tempXX;
  44.     private $tempYX;
  45.     private $tempXZ;
  46.     private $tempYZ;
  47.     private $iPerspec;
  48.     private $iOrthoX=0;
  49.     private $iOrthoY=0;
  50.     private $iZoomFactor=0;
  51.     private $iZoomPerspec=0;
  52.     private $pie3D;
  53.     private $colorPalette;
  54.  
  55.     private static $NUMCIRCLEPOINTS = 64;
  56.     public static $DARKCOLORQUANTITY = 64;
  57.     private static $DARKERCOLORQUANTITY = 128;
  58.  
  59.     // Protected properties
  60.     protected $aspect;
  61.     protected $smoothingMode=false;
  62.     protected $textSmooth=false;
  63.     protected $font=null;
  64.     protected $stringFormat;
  65.     protected $bounds;
  66.     protected $brush=null;
  67.     protected $pen=null;
  68.     protected $metafiling;
  69.     protected $imageinterlace=true;
  70.     protected $imagereflection=false;
  71.     // For CanvasFlex
  72.     protected $supportsID;
  73.  
  74.     // Public properties
  75.     public $img;
  76.     public $width=0;
  77.     public $height=0;
  78.     public $monochrome;
  79.     public $iPointDoubles;
  80.  
  81.  
  82.     // Interceptors
  83.     function __get( $property ) {
  84.       $method ="get{$property}";
  85.       if ( method_exists( $this, $method ) ) {
  86.         return $this->$method();
  87.       }
  88.     }
  89.  
  90.     function __set ( $property,$value ) {
  91.       $method ="set{$property}";
  92.       if ( method_exists( $this, $method ) ) {
  93.         return $this->$method($value);
  94.       }
  95.     }
  96.  
  97.     /**
  98.     * Creates a new Graphics object
  99.     *
  100.     * @access       public
  101.     * @param IBaseChart $c 
  102.     * @param integer $width 
  103.     * @param integer $height 
  104.     */
  105.     function GraphicsGD($c, $width, $height) {
  106.  
  107.         $this->font = new ChartFont(null);
  108.         $this->stringFormat = new StringFormat();
  109.         $this->brush = new ChartBrush(null,null,null);
  110.         $this->pen = new ChartPen(null,new Color(0,0,0));
  111. //        $this->colorPalette = Theme::getSkyBluesPalette();
  112.         $this->rotationCenter = new Point3D();
  113.  
  114.         $this->iPoints = array();
  115.         $this->iPoints[0]=new TeePoint();
  116.         $this->iPoints[1]=new TeePoint();
  117.         $this->iPoints[2]=new TeePoint();
  118.         $this->iPoints[3]=new TeePoint();
  119.  
  120.         $this->iPointDoubles = Array();
  121.         $this->iPointDoubles[0]= new PointDouble();
  122.         $this->iPointDoubles[1]= new PointDouble();
  123.         $this->iPointDoubles[2]= new PointDouble();
  124.         $this->iPointDoubles[3]= new PointDouble();
  125.  
  126.  
  127.         $this->width = $width;
  128.         $this->height= $height;
  129.  
  130.         parent::__construct($c);  // TeeBase
  131.        
  132.         if ($this->chart != null) {
  133.             $this->setAspect($this->chart->getAspect());            
  134.       }
  135.     }
  136.  
  137.     /**************************************************************************
  138.     * Drawing methods............                                             *
  139.     **************************************************************************/
  140.  
  141.     /**
  142.     * Paints the image in rectangle r.
  143.     *
  144.     * @param r Rectangle
  145.     * @param image Image
  146.     * @param mode ImageMode
  147.     * @param transparent boolean
  148.     */
  149.     public function draw($r, $image, $mode, $shapeBorders, $transparent) {
  150.  
  151.         imageAlphaBlending($image, false);
  152.         imageSaveAlpha($image, true);
  153.  
  154.         //Get the sizes of both pix
  155.         $sourcefile_width=imagesx($this->img);
  156.         $sourcefile_height=imagesy($this->img);
  157.         $image_width=imagesx($image);
  158.         $image_height=imagesy($image);
  159.  
  160.  
  161.         if ($mode==ImageMode::$TILE) {
  162.            // TODO
  163.         }
  164.         elseif ($mode==ImageMode::$CENTER) {
  165.             $dest_x = ( $sourcefile_width / 2 ) - ( $image_width / 2 );
  166.             $dest_y = ( $sourcefile_height / 2 ) - ( $image_height / 2 );
  167.             imagecopy($this->img, $image, $dest_x, $dest_y, 0, 0,
  168.                $image_width, $image_height);
  169.         }
  170.         elseif ($mode==ImageMode::$NORMAL) {
  171.             $dest_x = 0;
  172.             $dest_y = 0;
  173.  
  174.             imagecopy($this->img, $image, $dest_x, $dest_y, 0, 0,
  175.                $image_width, $image_height);
  176.         }
  177.         else{
  178.           // Streched
  179.           $dest_x = 0;
  180.           $dest_y = 0;
  181.  
  182.           imagecopyresized($this->img, $image,$dest_x, $dest_y, 0, 0,
  183.               $sourcefile_width, $sourcefile_height,
  184.               $image_width, $image_height);
  185.         }
  186.  
  187.         // Check Round borders
  188.         // Top-left corner
  189.         if (($shapeBorders->getTopLeft()->getBorderRound() > 0) || ($shapeBorders->getBottomLeft()->getBorderRound() > 0) ||
  190.             ($shapeBorders->getTopRight()->getBorderRound() > 0) || ($shapeBorders->getBottomRight()->getBorderRound() > 0)) {
  191.  
  192.               $this->drawRoundedBorders($shapeBorders,null,null);
  193.         }
  194.     }
  195.  
  196.     /**
  197.      * Draws a line with an arrow head of ArrowWidth and ArrowHeight dimensions
  198.      * in pixels.
  199.      *
  200.      * @param filled boolean
  201.      * @param fromPoint Point
  202.      * @param toPoint Point
  203.      * @param headWidth int
  204.      * @param headHeight int
  205.      * @param z int
  206.      */
  207.     public function arrow($filled, $fromPoint, $toPoint,
  208.                       $headWidth, $headHeight, $z) {
  209.         /*
  210.                                      pc |\
  211.                       ph             pf | \
  212.                            |------------   \ ToPoint
  213.                       From |------------   /
  214.                       pg             pe | /
  215.                                      pd |/
  216.          */
  217.  
  218.         $dx = $toPoint->getX() - $fromPoint->getX();
  219.         $dy = $fromPoint->getY() - $toPoint->getY();
  220.         $l = sqrt($dx * $dx + $dy * $dy);
  221.  
  222.         if ($l > 0) { // if at least one pixel...
  223.             $a = new ArrowPoint();
  224.             $a->z = $z;
  225.             $a->g = $this;
  226.  
  227.             (int) $tmpHoriz = $headWidth;
  228.             (int) $tmpVert = min(MathUtils::round($l), $headHeight);
  229.             $a->sinA = $dy / $l;
  230.             $a->cosA = $dx / $l;
  231.             $xb = $toPoint->getX() * $a->cosA - $toPoint->getY() * $a->sinA;
  232.             $yb = $toPoint->getX() * $a->sinA + $toPoint->getY() * $a->cosA;
  233.             $a->x = $xb - $tmpVert;
  234.             $a->y = $yb - $tmpHoriz * 0.5;
  235.  
  236.             $pc = $a->calc();
  237.             $a->y = $yb + $tmpHoriz * 0.5;
  238.             $pd = $a->calc();
  239.  
  240.             if ($filled) {
  241.                 $tmpHoriz4 = $tmpHoriz * 0.25;
  242.                 $a->y = $yb - $tmpHoriz4;
  243.                 $pe = $a->calc();
  244.                 $a->y = $yb + $tmpHoriz4;
  245.                 $pf = $a->calc();
  246.                 $a->x = $fromPoint->x * $a->cosA - $fromPoint->y * $a->sinA;
  247.                 $a->y = $yb - $tmpHoriz4;
  248.                 $pg = $a->calc();
  249.                 $a->y = $yb + $tmpHoriz4;
  250.                 $ph = $a->calc();
  251.                 
  252.                 $tmp = Array($ph, $pg, $pe, $pc, $this->calc3DPoint($toPoint->getX(),$toPoint->getY(),
  253.                     $z), $pd, $pf);
  254.                 $this->polygon($tmp);
  255.             } else {
  256.                 $this->moveToZ($fromPoint, $z);
  257.                 $this->lineTo($toPoint, $z);
  258.                 $this->lineTo($pd, $z);
  259.                 $this->moveToZ($toPoint, $z);
  260.                 $this->lineTo($pc, $z);
  261.             }
  262.         }
  263.     }
  264.  
  265.     /**
  266.      * Draws Bezier splines for the Point array p at displacement z
  267.      *
  268.      * @param z int
  269.      * @param p Point[]
  270.      */
  271.     public function drawBeziersRect($z, $p) {
  272.         $this->internalBezier($z, true, $p);
  273.     }
  274.         
  275.     /**
  276.      * Draws Bezier splines for the Point array p
  277.      *
  278.      * @param p Point[]
  279.      */
  280.     public function drawBeziers($p) {
  281.         $this->internalBezier(0, false, $p);
  282.     }
  283.     
  284.     private function internalBezier($z, $is3D, $points) {
  285.         if ($is3D) {
  286.             $this->moveToXYZ($points[0]->x, $points[0]->y, $z);
  287.         } else {
  288.             $this->moveTo($points[0]);
  289.         }
  290.  
  291.         $this->drawBezier($is3D, $z, $points, 2);
  292.         $t = 4;
  293.         do {
  294.             $this->drawBezier($is3D, $z, $points, $t);
  295.             $t += 2;
  296.         } while (!($t > sizeof($points) - 1));
  297.     }   
  298.     
  299.     private function drawBezier($is3D, $z, $points, $first) {
  300.  
  301.         $p1 = $points[$first - 2];
  302.         $p2 = $points[$first - 1];
  303.         $p3 = $points[$first];
  304.  
  305.         for ($t = 1; $t < 32; $t++) {
  306.             $mu = $t / 32;
  307.             $mu2 = $mu * $mu;
  308.             $mum1 = 1 - $mu;
  309.             $mum12 = $mum1 * $mum1;
  310.  
  311.             $p = new TeePoint((int) ($p1->x * $mum12 + 2 * $p2->x * $mum1 * $mu +
  312.                                        $p3->x * $mu2),
  313.                                 (int) ($p1->y * $mum12 + 2 * $p2->y * $mum1 * $mu +
  314.                                        $p3->y * $mu2));
  315.  
  316.             if ($is3D) {
  317.                 $this->lineTo($p, $z);
  318.             } else {
  319.                 $this->__lineTo($p);
  320.             }
  321.         }
  322.     }
  323.      
  324.             
  325.     /**
  326.      * Calculates and returns the XY position in pixels of the XYZ 3D
  327.      * coordinate.<br>
  328.      * Can be used when custom drawing using 3D XYZ coordinates are returned
  329.      * from the axes or not.
  330.      *
  331.      * @param x int
  332.      * @param y int
  333.      * @param z int
  334.      * @return Point 
  335.      */
  336.     public function calc3DPos($x, $y, $z) {
  337.         if ($this->isOrtho) {
  338.             return new TeePoint(($this->iZoomFactor * ($x - $this->xCenter +
  339.                    ($this->iOrthoX * $z))) + $this->xCenterOffset,
  340.                    ($this->iZoomFactor * ($y - $this->yCenter - ($this->iOrthoY *
  341.                    $z))) + $this->yCenterOffset);
  342.         } else
  343.         if ($this->is3D) {
  344.             $z -= $this->zCenter;
  345.             $x -= $this->xCenter;
  346.             $y -= $this->yCenter;
  347.  
  348.             $zz = $z * $this->c2 - $x * $this->s2;
  349.  
  350.             $tmp = $this->iZoomFactor;
  351.  
  352.             if ($this->iPerspec) {
  353.                 $tmp /= (1 + $this->iZoomPerspec * ($zz * $this->c1 + $y * $this->s1));
  354.             }
  355.  
  356.             return new TeePoint( (($x * $this->c2 + $z * $this->s2) * $tmp) + $this->xCenterOffset,
  357.                               (($y * $this->c1 - $zz * $this->s1) * $tmp) + $this->yCenterOffset);
  358.         } else {
  359.             return new TeePoint($x, $y);
  360.         }
  361.     }
  362.  
  363.     /**
  364.      * Calculates and returns the XY position as double of the XYZ 3D
  365.      * coordinate.<br>
  366.      * Can be used when custom drawing using 3D XYZ coordinates are returned
  367.      * from the axes or not.
  368.      * Returns PointDouble
  369.      */
  370.     public function calc3DPosDouble($x, $y, $z, $pointDouble) {
  371.         if ($this->isOrtho) {
  372.             return new PointDouble((int) ($this->iZoomFactor * ($x - $this->xCenter + ($this->iOrthoX * $z))) +
  373.                              $this->xCenterOffset,
  374.                              (int) ($this->iZoomFactor * ($y - $this->yCenter - ($this->iOrthoY * $z))) +
  375.                              $this->yCenterOffset);
  376.         } else
  377.         if ($this->is3D) {
  378.             $z -= $this->zCenter;
  379.             $x -= $this->xCenter;
  380.             $y -= $this->yCenter;
  381.  
  382.             $zz = $z * $this->c2 - $x * $this->s2;
  383.  
  384.             $tmp = $this->iZoomFactor;
  385.  
  386.             if ($this->iPerspec) {
  387.                 $tmp /= (1 + $this->iZoomPerspec * ($zz * $this->c1 + $y * $this->s1));
  388.             }
  389.  
  390.             return new PointDouble((int) (($x * $this->c2 + $z * $this->s2) * $tmp) + $this->xCenterOffset,
  391.                (int) (($y * $this->c1 - $zz * $this->s1) * $tmp) + $this->yCenterOffset);
  392.  
  393.         } else {
  394.             return new PointDouble($x, $y);
  395.         }
  396.     }
  397.  
  398.     /**
  399.      * Calculates and returns the XY position in pixels of the point p Z 3D
  400.      * coordinate. <br>
  401.      * Can be used when custom drawing using 3D XYZ coordinates are returned
  402.      * from the axes or not.
  403.      *
  404.      * @param source Point3D
  405.      * @return Point 
  406.      */
  407.     public function _calc3DPos($source) {
  408.         return $this->calc3DPos($source->getX(), $source->getY(), $source-getZ());
  409.     }
  410.  
  411.     /**
  412.      * Calculates and returns the XY position in pixels of the point p Z 3D
  413.      * coordinate.<br>
  414.      * Can be used when custom drawing using 3D XYZ coordinates are returned
  415.      * from the axes or not.
  416.      *
  417.      * @param source Point
  418.      * @param z int
  419.      * @return Point 
  420.      */
  421.     public function __calc3DPos($source, $z) {
  422.         return $this->calc3DPos($source->getX(), $source->getY(), $z);
  423.     }
  424.  
  425.     /**
  426.      * Calculates and returns the XY position in pixels of the point p with
  427.      * Z = 0 3D coordinate.<br>
  428.      * Can be used when custom drawing using 3D XYZ coordinates are returned
  429.      * from the axes or not.
  430.      *
  431.      * @param source Point
  432.      * @return Point 
  433.      */
  434.     public function ___calc3DPos($source) {
  435.         return $this->calc3DPos($source->x, $source->y, 0);
  436.     }
  437.  
  438.     public function calc3DPoint($x, $y, $z=0) {
  439.         return $this->calc3DPos($x, $y, $z);
  440.     }
  441.  
  442.     public function calcPerspective($r) {
  443.         $PERSPECFACTOR = 1.0 / 150.0;
  444.         $perspec = $this->aspect->getPerspective();
  445.         $this->iPerspec = ($perspec > 0);
  446.  
  447.         if ($this->iPerspec) {
  448.             $tmp = $r->width;
  449.             if ($tmp < 1) {
  450.                 $tmp = 1;
  451.             }
  452.  
  453.             $this->iZoomPerspec = $this->iZoomFactor * $perspec * $PERSPECFACTOR / $tmp;
  454.         }
  455.     }
  456.  
  457.     public function calcTrigValues() {
  458.         $rx = 0;
  459.         $ry = 0;
  460.         $rz = 0;
  461.  
  462.         if (!$this->aspect->getOrthogonal()) {
  463.             $rx = -$this->aspect->getElevation();
  464.             $ry = -$this->aspect->getRotation();
  465.             $rz = $this->aspect->getTilt();
  466.         }
  467.  
  468.         $this->s1 = sin($rx * MathUtils::getPiStep());
  469.         $this->c1 = cos($rx * MathUtils::getPiStep());
  470.  
  471.         $this->s2 = sin($ry * MathUtils::getPiStep());
  472.         $this->c2 = cos($ry * MathUtils::getPiStep());
  473.         $this->s3 = sin($rz * MathUtils::getPiStep());
  474.         $this->c3 = cos($rz * MathUtils::getPiStep());
  475.  
  476.         $this->c2s3 = $this->c2 * $this->s3;
  477.         $this->c2c3 = max(1E-5, $this->c2 * $this->c3);
  478.  
  479.         $this->tempXX = max(1E-5, $this->s1 * $this->s2 * $this->s3 + $this->c1 * $this->c3);
  480.         $this->tempYX = ($this->c3 * $this->s1 * $this->s2 - $this->c1 * $this->s3);
  481.  
  482.         $this->tempXZ = ($this->c1 * $this->s2 * $this->s3 - $this->c3 * $this->s1);
  483.         $this->tempYZ = ($this->c1 * $this->c3 * $this->s2 + $this->s1 * $this->s3);
  484.  
  485.         $this->iPerspec = false;
  486.         $this->iZoomPerspec = 0;
  487.     }
  488.  
  489.     public function changed($o) {}
  490.  
  491.     function unClip() {
  492.  
  493.       if (!$this->rectClip==null)
  494.       {
  495.         $x = $this->rectClip->getX();
  496.         $y = $this->rectClip->getY();
  497.         imagecopymerge($this->tmpImg, $this->img,$x,$y,$x,$y,
  498.         $this->rectClip->getWidth(),$this->rectClip->getHeight(),100);
  499.  
  500.         imagecopy($this->img,$this->tmpImg,0,0,0,0,imagesx($this->img),imagesy($this->img));
  501.         $this->rectClip=null;
  502.       }
  503.  
  504.       if (!$this->polygonClip==null)
  505.       {
  506.         // TODO polygon uniclip
  507.         $this->polygonClip=null;
  508.       }
  509.     }
  510.  
  511.     /**
  512.      * Creates a Windows GDI clipping region and selects it into
  513.      * TChart.<!-- -->Canvas device context handle.<br>
  514.      *
  515.      * @param left int
  516.      * @param top int
  517.      * @param right int
  518.      * @param bottom int
  519.      */
  520.     public function clipRectangle($left, $top, $right, $bottom) {
  521.  
  522.       $top=$top-2;
  523.       $bottom++;
  524.       $right=$right+2;
  525.  
  526.       $this->rectClip=new Rectangle();
  527.       $this->rectClip->x=$left;
  528.       $this->rectClip->y=$top;
  529.       $this->rectClip->width=$right-$left;
  530.       $this->rectClip->height=$bottom-$top;
  531.  
  532.       $this->tmpImg = imagecreatetruecolor(imagesx($this->img), imagesy($this->img));
  533.  
  534.       // Converts to Transparent image
  535.       imagesavealpha($this->tmpImg, true);
  536.  
  537.       /* TODO Re-check if required 
  538.       $trans_colour = imagecolorallocatealpha($this->tmpImg, 0, 0, 0, 127);
  539.       imagefill($this->tmpImg, 0, 0, $trans_colour);
  540.       */
  541.  
  542.       imagecopy($this->tmpImg,$this->img,0,0,0,0,imagesx($this->img),imagesy($this->img));
  543.     }
  544.        
  545.  
  546.     /**
  547.      * Creates a Windows GDI clipping region and selects it into
  548.      * TChart.<!-- -->Canvas device context handle.<br>
  549.      *
  550.      * @param polygonPoints - Array of TeePoints
  551.      */
  552.     public function clipPolygon($polygonPoints) {
  553.  
  554.       $this->polygonClip=Array();
  555.       $this->polygonClip=$polygonPoiints;
  556.  
  557.       // TODO clipPolygon
  558.     }
  559.     
  560.     
  561.     /**
  562.      * Paints a cone with Cone Percent.<br>
  563.      * Use <br>ONLY with OPENGL</b>.<br>
  564.      * This parameter varies the apex size
  565.      * as a percentage of the base.<br>
  566.      *
  567.      * @param vertical boolean
  568.      * @param r Rectangle
  569.      * @param z0 int
  570.      * @param z1 int
  571.      * @param darkSides boolean
  572.      * @param conePercent int varies the apex size as a percentage of the base.
  573.      */
  574.     public function cone($vertical, $r, $z0, $z1, $darkSides, $conePercent=0) {
  575.         $this->internalCylinder($vertical, $r, $z0, $z1, $darkSides, $conePercent);
  576.     }
  577.  
  578.     /**
  579.      * Draws cylinder toggle Boolean for vertical or horizontal cylinder.
  580.      *
  581.      * @param vertical boolean
  582.      * @param r Rectangle
  583.      * @param z0 int
  584.      * @param z1 int
  585.      * @param darkSides boolean
  586.      */
  587.     public function cylinder($vertical, $r, $z0, $z1, $darkSides) {
  588.         $this->internalCylinder($vertical, $r, $z0, $z1, $darkSides, 100);
  589.     }
  590.  
  591.     private function internalCylinder($vertical, $r, $z0, $z1, $dark3D, $conePercent) {
  592.  
  593.         $NUMCYLINDERSIDES = 16;   // 256
  594.         $STEP = 2.0 * M_PI / $NUMCYLINDERSIDES; 
  595.         $STEPCOLOR = 256 / $NUMCYLINDERSIDES;         // 512
  596.         
  597.         $poly = Array();
  598.         $tmpPoly = Array();
  599.           
  600.         $oldColor = $this->brush->getColor();
  601.           
  602.         (int) $zRadius = ($z1 - $z0) / 2;
  603.         (int) $tmpMidZ = ($z1 + $z0) / 2;
  604.  
  605.         if ($vertical) {
  606.             
  607.             (int) $radius = ($r->getRight() - $r->x) / 2;
  608.             (int) $tmpMid = ($r->getRight() + $r->x) / 2;
  609.             (int) $tmpSize = abs($r->getBottom() - $r->y);
  610.  
  611.             for ($t = 0; $t < $NUMCYLINDERSIDES; $t++) {
  612.                 (double) $tmpSin = sin(($t - 3) * $STEP);
  613.                 (double) $tmpCos = cos(($t - 3) * $STEP);
  614.  
  615.                 $poly[$t] = new Point3D();
  616.  
  617.                 $poly[$t]->x = $tmpMid + MathUtils::round($tmpSin * $radius);
  618.  
  619.                 if ($r->y < $r->getBottom()) {
  620.                     $poly[$t]->y = $r->y;
  621.                 } else {
  622.                     $poly[$t]->y = $r->getBottom();
  623.                 }
  624.  
  625.                 $poly[$t]->z = $tmpMidZ - MathUtils::round($tmpCos * $zRadius);
  626.             }
  627.             $radius = MathUtils::round($radius * $conePercent * 0.01);
  628.             $zRadius = MathUtils::round($zRadius * $conePercent * 0.01);
  629.  
  630.             $tmpPoly[1] = $this->calc3DPoint($poly[0]->x, $poly[0]->y + $tmpSize, $poly[0]->z);
  631.  
  632.             $tmpSin = sin((1 - 4) * $STEP);
  633.             $tmpCos = cos((1 - 4) * $STEP);
  634.  
  635.             $poly[0]->x = $tmpMid + MathUtils::round($tmpSin * $radius);
  636.             $poly[0]->z = $tmpMidZ - MathUtils::round($tmpCos * $zRadius);
  637.  
  638.             $tmpPoly[0] = $this->calc3DPoint($poly[0]->x,$poly[0]->y,$poly[0]->z);
  639.  
  640.             $numSide = 0;
  641.  
  642.             for ($t = 1; $t < $NUMCYLINDERSIDES; $t++) {
  643.                 $tmpPoly[2] = $this->calc3DPoint($poly[$t]->x, $poly[$t]->y + $tmpSize,
  644.                                          $poly[$t]->z);
  645.  
  646.                 $tmpSin = sin(($t - 3) * $STEP);
  647.                 $tmpCos = cos(($t - 3) * $STEP);
  648.  
  649.                 $poly[$t]->x = $tmpMid + MathUtils::round($tmpSin * $radius);
  650.                 $poly[$t]->z = $tmpMidZ - MathUtils::round($tmpCos * $zRadius);
  651.  
  652.                 $tmpPoly[3] = $this->calc3DPoint($poly[$t]->x,$poly[$t]->y,$poly[$t]->z);
  653.                 $tmp = ($tmpPoly[0]->x - $tmpPoly[2]->x + $tmpPoly[1]->x -
  654.                        $tmpPoly[3]->x) < 0;
  655.                 if ($tmp) {
  656.                     if ($dark3D) {                           
  657.                         $this->internalApplyDark($oldColor, $STEPCOLOR * $numSide);
  658.                     }
  659.  
  660.                     $p = Array($tmpPoly[0], $tmpPoly[1], $tmpPoly[2], $tmpPoly[3]);                    
  661.                     $this->polygon($p);
  662.                 }
  663.                 $tmpPoly[0] = $tmpPoly[3];
  664.                 $tmpPoly[1] = $tmpPoly[2];
  665.                 $numSide++;
  666.             }
  667.         } else {
  668.             $radius = ($r->getBottom() - $r->y) / 2;
  669.             $tmpMid = ($r->getBottom() + $r->y) / 2;      
  670.            
  671.             $tmpSize = $r->getRight() - $r->X;
  672.  
  673.             for ($t = 0; $t < $NUMCYLINDERSIDES; $t++) {
  674.                 $tmpSin = sin(($t - 4) * $STEP);
  675.                 $tmpCos = cos(($t - 4) * $STEP);
  676.  
  677.                 $poly[$t] = new Point3D();
  678.                          
  679.                 if ($r->x < $r->getRight()) {
  680.                     $poly[$t]->x = $r->getRight();
  681.                 } else {
  682.                     $poly[$t]->x = $r->x;
  683.                 }
  684.             
  685.                 $poly[$t]->y = $tmpMid + MathUtils::round($tmpSin * $radius);
  686.                 $poly[$t]->z = $tmpMidZ - MathUtils::round($tmpCos * $zRadius);
  687.             }
  688.  
  689.             $radius = MathUtils::round($radius * $conePercent * 0.01);
  690.             $zRadius = MathUtils::round($zRadius * $conePercent * 0.01);
  691.             $tmpSize = abs($r->getRight() - $r->x);
  692.  
  693.             $tmpPoly[1] = $this->calc3DPoint($poly[0]->x - $tmpSize, $poly[0]->y, $poly[0]->z);
  694.  
  695.             $tmpSin = sin( -4 * $STEP);
  696.             $tmpCos = cos( -4 * $STEP);
  697.  
  698.             $poly[0]->y = $tmpMid + MathUtils::round($tmpSin * $radius);
  699.             $poly[0]->z = $tmpMidZ - MathUtils::round($tmpCos * $zRadius);
  700.                           
  701.                         
  702.             $tmpPoly[0] = $this->calc3DPoint($poly[0]->x,$poly[0]->y,$poly[0]->z);
  703.             $numSide = 0;
  704.  
  705.             for ($t = 1; $t < $NUMCYLINDERSIDES; $t++) {
  706.                 $tmpPoly[2] = $this->calc3DPoint($poly[$t]->x - $tmpSize, $poly[$t]->y,
  707.                                          $poly[$t]->z);
  708.  
  709.                 $tmpSin = sin(($t - 4) * $STEP);
  710.                 $tmpCos = cos(($t - 4) * $STEP);
  711.  
  712.                 $poly[$t]->y = $tmpMid + MathUtils::round($tmpSin * $radius);
  713.                 $poly[$t]->z = $tmpMidZ - MathUtils::round($tmpCos * $zRadius);
  714.  
  715.                 $tmpPoly[3] = $this->calc3DPoint($poly[$t]->x,$poly[$t]->y,$poly[$t]->z);
  716.                 $tmp = ($tmpPoly[0]->y - $tmpPoly[2]->y + $tmpPoly[1]->y -
  717.                        $tmpPoly[3]->y) < 0;
  718.  
  719.                 if ($tmp) {
  720.                     if ($dark3D) {                
  721.                          $this->internalApplyDark($oldColor, $STEPCOLOR * $numSide);
  722.                     }                                                                  
  723.  
  724.                     $p = Array($tmpPoly[0], $tmpPoly[1], $tmpPoly[2], $tmpPoly[3]);
  725.                     $this->polygon($p);
  726.                 }
  727.  
  728.                 $tmpPoly[0] = $tmpPoly[3];
  729.                 $tmpPoly[1] = $tmpPoly[2];
  730.                 $numSide++;
  731.             }
  732.         }
  733.  
  734.         for ($t = 0; $t < $NUMCYLINDERSIDES; $t++) {
  735.             $tmpPoly[$t] = $this->calc3DPoint($poly[$t]->x,$poly[$t]->y,$poly[$t]->z);
  736.         }
  737.  
  738.         if ($dark3D) {
  739.             $this->internalApplyDark($oldColor, $DARKCOLORQUANTITY);
  740.         }
  741.  
  742.         $this->polygon($tmpPoly);
  743.     }
  744.     
  745.  
  746. function imagegradientellipse($image, $cx, $cy, $w, $h, $ic, $oc){
  747.     $w = abs($w);
  748.     $h = abs($h);
  749.     $oc = array(0xFF & ($oc >> 0x10), 0xFF & ($oc >> 0x8), 0xFF & $oc);
  750.     $ic = array(0xFF & ($ic >> 0x10), 0xFF & ($ic >> 0x8), 0xFF & $ic);
  751.     $c0 = ($oc[0] - $ic[0]) / $w;
  752.     $c1 = ($oc[1] - $ic[1]) / $w;
  753.     $c2 = ($oc[2] - $ic[2]) / $w;
  754.     $i = 0;
  755.     $j = 0;
  756.     $is = ($w<$h)?($w/$h):1;
  757.     $js = ($h<$w)?($h/$w):1;
  758.     while(1){
  759.         $r = $oc[0] - floor($i * $c0);
  760.         $g = $oc[1] - floor($i * $c1);
  761.         $b = $oc[2] - floor($i * $c2);
  762.         $c = imagecolorallocate($image, $r, $g, $b);
  763.         imagefilledellipse($image, $cx, $cy, $w-$i, $h-$j, $c);
  764.         if($i < $w){
  765.             $i += $is;
  766.         }
  767.         if($j < $h){
  768.             $j += $js;
  769.         }
  770.         if($i >= $w && $j >= $h){
  771.             break;
  772.         }
  773.     }
  774. }
  775.  
  776. function imagegradientellipsealpha($image, $cx, $cy, $w, $h, $ic, $oc){
  777.        $w = abs($w);
  778.        $h = abs($h);
  779.        $oc = array(0xFF & ($oc >> 0x10), 0xFF & ($oc >> 0x8), 0xFF & $oc);
  780.        $ic = array(0xFF & ($ic >> 0x10), 0xFF & ($ic >> 0x8), 0xFF & $ic);
  781.        $c0 = ($oc[0] - $ic[0]) / $w;
  782.        $c1 = ($oc[1] - $ic[1]) / $w;
  783.        $c2 = ($oc[2] - $ic[2]) / $w;
  784.        $ot = $oc >> 24;
  785.        $it = $ic >> 24;
  786.        $ct = ($ot - $it) / $w;
  787.        $i = 0;
  788.        $j = 0;
  789.        $is = ($w<$h)?($w/$h):1;
  790.        $js = ($h<$w)?($h/$w):1;
  791.        while(1){
  792.            $r = $oc[0] - floor($i * $c0);
  793.            $g = $oc[1] - floor($i * $c1);
  794.            $b = $oc[2] - floor($i * $c2);
  795.            $t = $ot - floor($i * $ct);
  796.            $c = imagecolorallocatealpha($image, $r, $g, $b, $t);
  797.            imageellipse($image, $cx, $cy, $w-$i, $h-$j, $c);
  798.            if($i < $w){
  799.                $i += $is;
  800.            }
  801.            if($j < $h){
  802.                $j += $js;
  803.            }
  804.            if($i >= $w && $j >= $h){
  805.                break;
  806.            }
  807.        }
  808.     }
  809.     
  810.     
  811.     private function clipToRight($rect, $minZ, $maxZ) {
  812.         $p = Array();
  813.         $p[0] = new TeePoint();
  814.         $p[1] = new TeePoint();
  815.         $p[2] = new TeePoint();
  816.         $p[3] = new TeePoint();
  817.         $p[4] = new TeePoint();
  818.         $p[5] = new TeePoint();
  819.  
  820.  
  821.         $p[0] = $this->calc3DPoint($rect->x, $rect->getBottom(), $minZ);
  822.         $p[1] = $this->calc3DPoint($rect->x, $rect->y, $minZ);
  823.  
  824.         {
  825.             $pa = $this->calc3DPoint($rect->x, $rect->y, $maxZ);
  826.             $pb = $this->calc3DPoint($rect->getRight(), $rect->y, $minZ);
  827.  
  828.             $p[2] = ($pb->getY() < $pa->getY()) ? $pb : $pa;
  829.         }
  830.  
  831.         $p[3] = $this->calc3DPoint($rect->getRight(), $rect->y, $maxZ);
  832.  
  833.         $pc = $this->calc3DPoint($rect->getRight(), $rect->getBottom(), $maxZ);
  834.         $pd = $this->calc3DPoint($rect->getRight(), $rect->y, $minZ);
  835.  
  836.         $p[4] = ($pd->getX() > $pc->getX()) ? $pd : $pc;
  837.  
  838.         $p[5] = $this->calc3DPoint($rect->getRight(), $rect->getBottom(), $minZ);
  839.         if ($p[5]->getX() < $p[0]->getX()) {
  840.             $p[0]->setX($p[5]->getX());
  841.             if ($pd->getY() < $p[0]->getY()) {
  842.                 $p[0]->setY($pd->getY());
  843.             }
  844.         }
  845.  
  846.         $c1 = imagecolorallocate($this->img, $this->getBrush()->getColor()->red,
  847.             $this->getBrush()->getColor()->green,
  848.             $this->getBrush()->getColor()->blue);
  849.     }
  850.  
  851.     private function clipToLeft($rect, $minZ, $maxZ) {
  852.  
  853.         $c1 = imagecolorallocate($this->img, $this->getBrush()->getColor()->red,
  854.             $this->getBrush()->getColor()->green,
  855.             $this->getBrush()->getColor()->blue);
  856.  
  857.         /* TODO 
  858.                 clippolygon  imagepolygon($this->img,  array (
  859.                     $this->calc3DPoint($rect->x, $rect->getBottom(), $minZ),
  860.                     $this->calc3DPoint($rect->x, $rect->getBottom(), $maxZ),
  861.                     $this->calc3DPoint($rect->x, $rect->y, $maxZ),
  862.                     $this->calc3DPoint($rect->getRight(), $rect->y, $maxZ),
  863.                     $this->calc3DPoint($rect->getRight(), $rect->y, $minZ),
  864.                     $this->calc3DPoint($rect->getRight(), $rect->getBottom(), $minZ)),
  865.                     3, $c1);
  866.         */
  867.     }
  868.  
  869.     public function cuber ($rect, $z0, $z1, $darkSides) {
  870.         $this->cube($rect->getLeft(), $rect->getTop(), $rect->getRight(), $rect->getBottom(), $z0, $z1, $darkSides);
  871.     }
  872.  
  873.     /**
  874.      * Draws a Cube with Dark Sides.
  875.      *
  876.      * @param left int
  877.      * @param top int
  878.      * @param right int
  879.      * @param bottom int
  880.      * @param z0 int
  881.      * @param z1 int
  882.      * @param darkSides boolean
  883.      */
  884.     public function cube($left, $top, $right, $bottom, $z0, $z1, $darkSides) {
  885.         $oldColor = $this->brush->getColor();
  886.         $p0 = $this->calc3DPoint($left, $top, $z0);
  887.         $p1 = $this->calc3DPoint($right, $top, $z0);
  888.         $p2 = $this->calc3DPoint($right, $bottom, $z0);
  889.         $p3 = $this->calc3DPoint($right, $top, $z1);
  890.         $this->iPoints[0] = $p0;
  891.         $this->iPoints[1] = $p1;
  892.         $this->iPoints[2] = $p2;
  893.         $this->iPoints[3] = $this->calc3DPoint($left, $bottom, $z0);
  894.  
  895.         if ($this->culling() > 0) {
  896.             $this->polygonFour(); // front-side
  897.         } else {
  898.             $this->iPoints[0] = $this->calc3DPos($left, $top, $z1);
  899.             $this->iPoints[1] = $this->calc3DPos($right, $top, $z1);
  900.             $this->iPoints[2] = $this->calc3DPos($right, $bottom, $z1);
  901.             $this->iPoints[3] = $this->calc3DPos($left, $bottom, $z1);
  902.             $this->polygonFour(); // back-side
  903.         }
  904.  
  905.         $this->iPoints[2] = $this->calc3DPos($right, $bottom, $z1);
  906.         $this->iPoints[0] = $p1;
  907.         $this->iPoints[1] = $p3;
  908.         $this->iPoints[3] = $p2;
  909.  
  910.         if ($this->culling() > 0) {
  911.             if ($darkSides) {
  912.                 $this->internalApplyDark($oldColor, self::$DARKERCOLORQUANTITY);
  913.             }
  914.             $this->polygonFour(); // left-side
  915.         }
  916.  
  917.         $this->iPoints[0] = $p0;
  918.         $this->iPoints[1] = $this->calc3DPos($left, $top, $z1);
  919.         $this->iPoints[2] = $this->calc3DPos($left, $bottom, $z1);
  920.         $this->iPoints[3] = $this->calc3DPos($left, $bottom, $z0);
  921.  
  922.         $tmp = ($this->iPoints[3]->getX() - $this->iPoints[0]->getX()) *
  923.                      ($this->iPoints[1]->getY() - $this->iPoints[0]->getY()) -
  924.                      ($this->iPoints[1]->getX() - $this->iPoints[0]->getX()) *
  925.                      ($this->iPoints[3]->getY() - $this->iPoints[0]->getY());
  926.  
  927.         if ($tmp > 0) {
  928.             if ($darkSides) {
  929.                 $this->internalApplyDark($oldColor, self::$DARKERCOLORQUANTITY);
  930.             }
  931.             $this->polygonFour(); // right-side
  932.         }
  933.  
  934.         $this->iPoints[3] = $this->calc3DPos($left, $top, $z1);
  935.  
  936.         // culling
  937.         $tmp = ($p0->getX() - $p1->getX()) * ($p3->getY() - $p1->getY()) -
  938.             ($p3->getX() - $p1->getX()) * ($p0->getY() - $p1->getY());
  939.         if ($tmp > 0) {
  940.             $this->iPoints[0] = $p0;
  941.             $this->iPoints[1] = $p1;
  942.             $this->iPoints[2] = $p3;
  943.             if ($darkSides) {
  944.                 $this->internalApplyDark($oldColor, self::$DARKCOLORQUANTITY);
  945.             }
  946.             $this->polygonFour(); // top-side
  947.         }
  948.  
  949.         $this->iPoints[0] = $this->calc3DPos($left, $bottom, $z0);
  950.         $this->iPoints[2] = $this->calc3DPos($right, $bottom, $z1);
  951.         $this->iPoints[1] = $this->calc3DPos($left, $bottom, $z1);
  952.  
  953.         $this->iPoints[3] = $p2;
  954.         if ($this->culling() < 0) {
  955.             if ($darkSides) {
  956.                 $this->internalApplyDark($oldColor, self::$DARKCOLORQUANTITY);
  957.             }
  958.             $this->polygonFour();
  959.         }
  960.  
  961.         $this->brush->setColor($oldColor);
  962.     }
  963.  
  964.     /**
  965.      * Creates a cubic Windows GDI clipping region.
  966.      *
  967.      * @param rect Rectangle
  968.      * @param minZ int
  969.      * @param maxZ int
  970.      */
  971.     public function clipCube($rect, $minZ, $maxZ) {
  972.  
  973.         if ($this->is3D) {
  974.             if ($this->aspect->getElevation() == 270) {
  975.                 if (($this->aspect->getRotation() == 270) ||
  976.                     ($this->aspect->getRotation() == 360)) {
  977.                     $tmpLT = $this->calc3DPoint($rect->x, $rect->y, $minZ);
  978.                     $tmpRB = $this->calc3DPoint($rect->getRight(), $rect->y, $maxZ);
  979.                     $this->clipRectangle($tmpLT->x, $tmpLT->y, $tmpRB->x, $tmpRB->y);
  980.                     return;
  981.                 }
  982.             }
  983.  
  984.             if ($this->isOrtho) {
  985.                 if ($this->aspect->getOrthoAngle() > 90) {
  986.                     $this->clipToLeft($rect, $minZ, $maxZ);
  987.                 } else {
  988.                     $this->clipToRight($rect, $minZ, $maxZ);
  989.                 }
  990.             } else
  991.             if ($this->aspect->getRotation() >= 270) {
  992.                 $this->clipToRight($rect, $minZ, $maxZ);
  993.             }
  994.         } else {
  995.             $this->clipRectangle($rect->x + 1, $rect->y + 1, $rect->getRight() - 1,
  996.                           $rect->getBottom() - 1);
  997.         }
  998.     }
  999.  
  1000.     private function culling() {
  1001.         return (($this->iPoints[3]->getX() - $this->iPoints[2]->getX()) * ($this->iPoints[1]->getY() -
  1002.             $this->iPoints[2]->getY())) - (($this->iPoints[1]->getX() - $this->iPoints[2]->getX()) *
  1003.             ($this->iPoints[3]->getY() - $this->iPoints[2]->getY()));
  1004.     }
  1005.  
  1006.     /**
  1007.     * Creates and initialize the image
  1008.     * @access       protected
  1009.     */
  1010.     function createImage()
  1011.     {
  1012.         $this->img = imagecreatetruecolor($this->width, $this->height);
  1013.  
  1014.         // Converts to Transparent image
  1015.         imagesavealpha($this->img, true);
  1016.  
  1017.         /* Check if following line must be added for round borders
  1018.         $trans_colour = imagecolorallocatealpha($this->img, 0, 0, 0, 127);
  1019.         imagefill($this->img, 0, 0, $trans_colour);
  1020.         */
  1021.  
  1022.         $this->textColor = new Color(0, 0, 0);
  1023.         return $this->img;
  1024.     }
  1025.  
  1026.     private function doBevelRect($rect, $a, $b) {
  1027.         $topRight = new TeePoint($rect->getRight() - 1, $rect->y);
  1028.         $bottomLeft = new TeePoint($rect->x, $rect->getBottom() - 1);
  1029.         $bottomRight = new TeePoint($rect->getRight() - 1, $rect->getBottom() - 1);
  1030.  
  1031.         $this->___line($a, $rect->getLocation(), $topRight);
  1032.         $this->___line($a, $rect->getLocation(), $bottomLeft);
  1033.         $this->___line($b, $bottomLeft, $bottomRight);
  1034.         $this->___line($b, $bottomRight, $topRight);
  1035.     }
  1036.  
  1037.     public function doRev() {
  1038.         $black = imagecolorallocate($this->img, 150, 150, 150);
  1039.         $x = imagesx($this->img);
  1040.         $y = imagesy($this->img)-6;
  1041.  
  1042.         $text = "EVALUATION VERSION";
  1043.         $font_file = ChartFont::$DEFAULTFAMILY;
  1044.         imagefttext($this->img, 25, 45, 25, $y+3, $black, $font_file, $text);
  1045.     }
  1046.  
  1047.     /**
  1048.      * Draws an Ellipse bounding Rectangle r.
  1049.      *
  1050.      * @param r Rectangle
  1051.      */
  1052.     public function ellipseRect($r) {
  1053.         $this->ellipse($r->getX(), $r->getY(), $r->getRight(), $r->getBottom());
  1054.     }
  1055.  
  1056.     /**
  1057.      * Ellipse bounding Rectangle r at z depth.
  1058.      *
  1059.      * @param r Rectangle
  1060.      * @param z int
  1061.      */
  1062.     public function ellipseRectZ($r, $z) {
  1063.         $this->ellipse($r->getX(), $r->getY(), $r->getRight(), $r->getBottom(), $z);
  1064.     }
  1065.  
  1066.     // DrawZone
  1067.     public function transparentEllipseZ($x1, $y1, $x2, $y2, $z) {
  1068.         $p1 = $this->calc3DPos($x1, $y1, $z);
  1069.         $p2 = $this->calc3DPos($x2, $y2, $z);
  1070.         $this->transparentEllipsePoints($p1, $p2);
  1071.     }
  1072.  
  1073.     protected function transparentEllipsePoints($p0, $p1) {
  1074.         $this->transparentEllipse($p0->getX(), $p0->getY(), $p1->getX(), $p1->getY());
  1075.     }
  1076.  
  1077.     /**
  1078.      * Ellipse bounding Rect (X1,Y1,X2,Y2) at Z position at angle.
  1079.      *
  1080.      * @param x1 int
  1081.      * @param y1 int
  1082.      * @param x2 int
  1083.      * @param y2 int
  1084.      * @param z int
  1085.      * @param angle double
  1086.  
  1087.      */
  1088.     public function ellipse($x1, $y1, $x2, $y2, $z=0, $angle=0) {
  1089.       if($z>0) {
  1090.         $p1 = $this->calc3DPos($x1, $y1, $z);
  1091.         $p2 = $this->calc3DPos($x2, $y2, $z);
  1092.         $this->ellipsePoints($p1,$p2);
  1093.        //  TODO - Here draw directly the ellipse with p1 and p2 $this->ellipsePoints($p1, $p2);
  1094.       }
  1095.       else
  1096.       {
  1097.         if ($angle>0) {
  1098.         $p = Array();
  1099.  
  1100.         $points = Array();
  1101.         for ($t = 0; $t < 3; $t++) {
  1102.             $points[$t] = new TeePoint();
  1103.         }
  1104.  
  1105.         $xCenter = ($x2 + $x1) * 0.5;
  1106.         $yCenter = ($y2 + $y1) * 0.5;
  1107.         $xRadius = ($x2 - $x1) * 0.5;
  1108.         $yRadius = ($y2 - $y1) * 0.5;
  1109.  
  1110.         $angle *= M_PI / 180.0;
  1111.  
  1112.         $tmpPiStep = 2 * M_PI / (self::$NUMCIRCLEPOINTS - 1);
  1113.  
  1114.         // initial rotation (rotation matrix elements)
  1115.         $tmpSinAngle = sin($angle);
  1116.         $tmpCosAngle = cos($angle);
  1117.  
  1118.         for ($t = 0; $t < self::$NUMCIRCLEPOINTS; $t++) {
  1119.             $tmpSin = sin($t * $tmpPiStep);
  1120.             $tmpCos = cos($t * $tmpPiStep);
  1121.             $tmpX = $xRadius * $tmpSin;
  1122.             $tmpY = $yRadius * $tmpCos;
  1123.  
  1124.             $p[$t] = new TeePoint(
  1125.                     MathUtils::round($xCenter +
  1126.                                           ($tmpX * $tmpCosAngle +
  1127.                                            $tmpY * $tmpSinAngle)),
  1128.                     MathUtils::round($yCenter +
  1129.                                           ( -$tmpX * $tmpSinAngle +
  1130.                                            $tmpY * $tmpCosAngle))
  1131.                    );
  1132.         }
  1133.  
  1134.         if ($this->getBrush()->getVisible()) {
  1135.             $old = $this->getPen()->getVisible();
  1136.             $this->getPen()->setVisible(false);
  1137.  
  1138.             $xc = MathUtils::round($xCenter);
  1139.             $yc = MathUtils::round($yCenter);
  1140.  
  1141.             for ($t = 1; $t < self::$NUMCIRCLEPOINTS; $t++) {
  1142.                 // has to be in loop because the Polygon
  1143.                 // transforms the positions from 3d to 2d in each pass
  1144.                 $points[0]->setX($xc);
  1145.                 $points[0]->setY($yc);
  1146.                 $points[1] = $p[$t - 1];
  1147.                 $points[2] = $p[$t];
  1148.                 $this->polygonz($z, $points);
  1149.             }
  1150.             // close it up with polygon from last to first
  1151.             $points[0]->setX($xc);
  1152.             $points[0]->setY($yc);
  1153.             $points[1] = $p[self::$NUMCIRCLEPOINTS - 1];
  1154.             $points[2] = $p[0];
  1155.             $this->polygonz($z, $points);
  1156.  
  1157.             $this->getPen()->setVisible($old);
  1158.         }
  1159.         if ($this->getPen()->getVisible()) {
  1160.             $this->polyLine($z, $p);
  1161.         }
  1162.         }
  1163.         else
  1164.         {
  1165.           $color = imagecolorallocate($this->img, $this->getBrush()->getColor()->red,
  1166.                                                   $this->getBrush()->getColor()->green,
  1167.                                                   $this->getBrush()->getColor()->blue);
  1168.  
  1169.           // updates x,y,width,height to be used in imagefilledellipse correctly
  1170.           $x1=$x1+(($x2-$x1) / 2);
  1171.           $y1=$y1+(($y2-$y1) / 2);
  1172.           $tmpWidth=($x2-$x1)*2;
  1173.           $tmpHeight=($y2-$y1)*2;
  1174.  
  1175.           if ($this->brush->getVisible()) {
  1176.             imagefilledellipse($this->img,$x1,$y1,$tmpWidth,$tmpHeight,$color);
  1177.           }
  1178.  
  1179.          if ($this->getPen()->getVisible()) {
  1180.             // Gets the pen color and style (dot , dashed, ...)
  1181.             $penColorStyle = $this->getPenColorStyle();
  1182.             imagesetstyle($this->img, $penColorStyle);
  1183.  
  1184.             // Assign the pen width for the image
  1185.             imagesetthickness ( $this->img, $this->pen->getWidth());
  1186.                         
  1187.             for ($i=0;$i<=$this->pen->getWidth();$i++)
  1188.               imageellipse($this->img,$x1,$y1,$tmpWidth+$i,$tmpHeight+$i,IMG_COLOR_STYLED);
  1189.           }
  1190.         }
  1191.       }
  1192.     }
  1193.  
  1194.     public function ellipsePoints($p0, $p1) {
  1195.         $this->ellipse($p0->getX(), $p0->getY(), $p1->getX(), $p1->getY());
  1196.     }
  1197.  
  1198.     /**
  1199.      * Ellipse bounding rectangle r with Z offset at angle.
  1200.      *
  1201.      * @param r Rectangle
  1202.      * @param z int
  1203.      * @param angle double
  1204.      */
  1205.     public function ellipseRectZAngle($r, $z, $angle=0) {
  1206.         $this->ellipse($r->getX(), $r->getY(), $r->getWidth(),
  1207.             $r->getHeight(), $z, $angle); // $r->getRight(), $r->getBottom(), $z, $angle);
  1208.     }
  1209.  
  1210.     /**
  1211.      * Determines the Font Height to be used for outputted text when using the
  1212.      * Drawing.
  1213.      *
  1214.      * @param f ChartFont
  1215.      * @return int 
  1216.      */
  1217.     public function fontTextHeight($f) {
  1218.         return $this->textHeight($f, "W");
  1219.     }
  1220.  
  1221.     public function initWindow($a, $r, $maxDepth) {
  1222.         $this->bounds = new Rectangle($r->x,$r->y,$r->width,$r->height);
  1223.         $this->setAspect($a);
  1224.         $this->iZoomFactor = 1;
  1225.  
  1226.         if ($this->is3D) {
  1227.             if ($this->isOrtho) {
  1228.                 $tmpAngle = $this->aspect->getOrthoAngle();
  1229.                 if ($tmpAngle > 90) {
  1230.                     $this->iOrthoX = -1;
  1231.                     $tmpAngle = 180 - $tmpAngle;
  1232.                 } else {
  1233.                     $this->iOrthoX = 1;
  1234.                 }
  1235.  
  1236.                 $tmpSin = sin($this->aspect->getOrthoAngle() *
  1237.                                          MathUtils::getPiStep());
  1238.                 $tmpCos = cos($this->aspect->getOrthoAngle() *
  1239.                                          MathUtils::getPiStep());
  1240.                 $this->iOrthoY = ($tmpCos < 0.01) ? 1 : $tmpSin / $tmpCos;
  1241.             }
  1242.             $this->iZoomFactor = 0.01 * $this->aspect->getZoom();
  1243.             $this->iZoomText = $this->aspect->getZoomText();
  1244.         }
  1245.  
  1246.         $this->calcTrigValues();
  1247.     }
  1248.  
  1249.     public function internalApplyDark($c, $quantity) {
  1250.         $this->brush->_applyDark($c, $quantity);
  1251.     }
  1252.  
  1253.     /**
  1254.     * Draws a straight line
  1255.     *
  1256.     * @access       public
  1257.     * @param        integer         line start (X)
  1258.     * @param        integer         line start (Y)
  1259.     * @param        integer         line end (X)
  1260.     * @param        integer         line end (Y)
  1261.     * @param        Color           line color
  1262.     * @param        integer         line width
  1263.     */
  1264.  
  1265.     function line($x1, $y1, $x2, $y2, $color=null, $width = -1)
  1266.     {
  1267.         /*if ($color==null)
  1268.         {
  1269.           $color = imagecolorallocate($this->img, $this->pen->getColor()->red,
  1270.           $this->pen->getColor()->green,
  1271.           $this->pen->getColor()->blue);
  1272.         }
  1273.         */
  1274.  
  1275.         imageantialias($this->img,false);          
  1276.         // Gets the pen color and style (dot , dashed, ...)
  1277.         $penColorStyle = $this->getPenColorStyle();
  1278.         imagesetstyle($this->img, $penColorStyle);
  1279.       
  1280.         // Assign the pen width for the image
  1281.         /* Set thickness. */
  1282.         if ($width==-1) {
  1283.           $width = $this->pen->getWidth();
  1284. //          if ($width < 2)
  1285. //            imageantialias($this->img,true);
  1286.  
  1287.           imagesetthickness ($this->img, $width);
  1288.         }
  1289.         else
  1290.         {
  1291. //          if ($width < 2)
  1292. //            imageantialias($this->img,true);
  1293.  
  1294.           imagesetthickness ($this->img, $width);
  1295.         }
  1296.                
  1297.         imageline($this->img, $x1, $y1, $x2, $y2, IMG_COLOR_STYLED);
  1298.   //      if ($width < 2)
  1299. //          imageantialias($this->img,false);
  1300.  
  1301.         imageantialias($this->img,true);
  1302.     }
  1303.  
  1304.     /**
  1305.     * Draws a Line between co-ordinates with z depth offset.
  1306.     *
  1307.     * @param x0 int
  1308.     * @param y0 int
  1309.     * @param x1 int
  1310.     * @param y1 int
  1311.     * @param z int
  1312.     */
  1313.     public function _line($x0, $y0, $x1, $y1, $z=0) {
  1314.         $this->__line($this->calc3DPos($x0, $y0, $z), $this->calc3DPos($x1, $y1, $z));
  1315.     }
  1316.  
  1317.     /**
  1318.     * Draws a Line between point p0 and point p1.
  1319.     *
  1320.     * @param p0 Point is origin xy
  1321.     * @param p1 Point is destination xy
  1322.     */
  1323.     public function __line($p0, $p1) {
  1324.         $this->line($p0->getX(), $p0->getY(), $p1->getX(), $p1->getY());
  1325.         // Move the mouse point
  1326.         $this->moveToXY($p1->getX(),$p1->getY());     // review
  1327.     }
  1328.  
  1329.     /**
  1330.     * Draws a Line between point p0 and point p1 using specific pen.
  1331.     *
  1332.     * @param pen ChartPen id the pen used
  1333.     * @param p0 Point is origin xy
  1334.     * @param p1 Point is destination xy
  1335.     */
  1336.     public function ___line($pen, $p0, $p1) {
  1337.  
  1338.         $oldPen = $this->getPen();
  1339.         $this->setPen($pen);
  1340.  
  1341.         // Gets the pen color and style (dot , dashed, ...)
  1342.         $penColorStyle = $this->getPenColorStyle();
  1343.         imagesetstyle($this->img, $penColorStyle);
  1344.  
  1345.         // Assign the pen width for the image
  1346.         imagesetthickness ( $this->img, $this->pen->getWidth());
  1347.  
  1348.         imageline($this->img, $p0->getX(),$p0->getY(),$p1->getX(),$p1->getY(),
  1349.             IMG_COLOR_STYLED);
  1350.  
  1351.         $this->setPen($oldPen);
  1352.     }
  1353.  
  1354.     /**
  1355.      * Draws a line to Point with z depth offset.
  1356.      *
  1357.      * @param p Point
  1358.      * @param z int
  1359.      */
  1360.     public function lineTo($p, $z) {
  1361.         $this->___lineTo($p->getX(), $p->getY(), $z);
  1362.     }
  1363.  
  1364.     /**
  1365.      * Draws a line to Point with z = 0 depth offset.
  1366.      *
  1367.      * @param p Point
  1368.      */
  1369.     public function __lineTo($p) {
  1370.         $this->line($this->moveToX, $this->moveToY ,$p->getX(), $p->getY());
  1371.  
  1372.         // Move the mouse point
  1373.         $this->moveToXY($p->getX(),$p->getY());
  1374.     }
  1375.  
  1376.     /**
  1377.      * Draws line from present position to end co-ordinates with z depth offset.
  1378.      *
  1379.      * @param x int
  1380.      * @param y int
  1381.      * @param z int
  1382.      */
  1383.     public function ___lineTo($x, $y, $z=0) {
  1384.         $this->__lineTo($this->calc3DPos($x, $y, $z));
  1385.     }
  1386.  
  1387.     /**
  1388.      * Draws a Line to 3D Point.
  1389.      *
  1390.      * @param p Point3D
  1391.      */
  1392.     public function ____lineTo($p) {
  1393.         $this->__lineTo($this->calc3DPos($p->getX(), $p->getY(), $p->getZ()));
  1394.     }
  1395.  
  1396.     /**
  1397.      * Draws line from present position to end co-ordinates with z depth offset.
  1398.      *
  1399.      * @param x int
  1400.      * @param y int
  1401.      */
  1402.     public function _____lineTo($x, $y) {
  1403.         $this->line($this->moveToX, $this->moveToY ,$x, $y);
  1404.         // Move the mouse point
  1405.         $this->moveToXY($x,$y);   // review
  1406.     }
  1407.  
  1408.     /**
  1409.      * Sets the value of PenPos to x and y co-ordinates  before calling LineTo.
  1410.      *
  1411.      * @param x int
  1412.      * @param y int
  1413.      */
  1414.     public function moveToXY($x, $y) {
  1415.         $this->moveToX=$x;
  1416.         $this->moveToY=$y;
  1417.     }
  1418.  
  1419.     /**
  1420.      * Sets the value of PenPos to Point p before calling LineTo.
  1421.      *
  1422.      * @param p Point
  1423.      */
  1424.     public function moveTo($p) {
  1425.         $this->moveToXY($p->getX(), $p->getY());
  1426.     }
  1427.  
  1428.     /**
  1429.      * Sets the value of PenPos to x, y and z co-ordinates before calling
  1430.      * LineTo.
  1431.      *
  1432.      * @param x int
  1433.      * @param y int
  1434.      * @param z int
  1435.      */
  1436.     public function moveToXYZ($x, $y, $z) {
  1437.         $p = $this->calc3DPos($x, $y, $z);
  1438.         $this->moveTo($p);
  1439.     }
  1440.  
  1441.     /**
  1442.      * Sets the value of PenPos to Point p  with z depth offset before calling
  1443.      * LineTo.
  1444.      *
  1445.      * @param p Point
  1446.      * @param z int
  1447.      */
  1448.     public function moveToZ($p, $z) {
  1449.         $p2 = $this->calc3DPos($p->getX(), $p->getY(), $z);
  1450.         $this->moveTo($p2);
  1451.     }
  1452.  
  1453.     /**
  1454.      * Sets the value of PenPos  to 3D Point p before calling LineTo.
  1455.      *
  1456.      * @param p Point3D
  1457.      */
  1458.     public function moveTo3D($p) {
  1459.         $this->moveTo($this->calc3DPos($p->getX(),$p->getY(), 0));
  1460.     }
  1461.  
  1462.     /**
  1463.     * Draws a Line from (X,Y,Z0) to (X,Y,Z1).
  1464.     *
  1465.     * @param x int
  1466.     * @param y int
  1467.     * @param z0 int
  1468.     * @param z1 int
  1469.     */
  1470.     public function zLine($x, $y, $z0, $z1) {
  1471.         $c1 = imagecolorallocatealpha($this->img, $this->pen->getColor()->red,
  1472.             $this->pen->getColor()->green,
  1473.             $this->pen->getColor()->blue,
  1474.             $this->pen->getColor()->alpha);
  1475.  
  1476.         $p1=$this->calc3DPos($x, $y, $z0);
  1477.         $p2=$this->calc3DPos($x, $y, $z1);
  1478.  
  1479.         imagesetthickness ( $this->img, $this->pen->getWidth());
  1480.         imageline($this->img, $p1->getX(),$p1->getY(),$p2->getX(),$p2->getY(),$c1);
  1481.     }
  1482.  
  1483.     /**
  1484.      * Draws a Horizontal at z depth position.
  1485.      *
  1486.      * @param left int
  1487.      * @param right int
  1488.      * @param y int
  1489.      * @param z int
  1490.      */
  1491.     public function horizontalLine($left, $right, $y, $z=0) {
  1492.         
  1493.         $c1 = imagecolorallocatealpha($this->img, $this->pen->getColor()->red,
  1494.             $this->pen->getColor()->green,
  1495.             $this->pen->getColor()->blue,
  1496.             $this->pen->getColor()->alpha);
  1497.                     
  1498.         $p1=$this->calc3DPos($left, $y, $z);
  1499.         $p2=$this->calc3DPos($right, $y, $z);
  1500.                 
  1501.         // Gets the pen color and style (dot , dashed, ...)
  1502.         $penColorStyle = $this->getPenColorStyle();
  1503.  
  1504.         // WORKAROUND for legend symbol when series lines and legend custom position true
  1505.         if ($this->getPen()->getStyle() != DashStyle::$SOLID)         
  1506.           imagesetstyle($this->img, $penColorStyle);
  1507.  
  1508.         // Assign the pen width for the image
  1509.         //  if ($this->getPen()->getWidth()>1)
  1510.           imagesetthickness ( $this->img, $this->pen->getWidth());
  1511.                                                                       
  1512.         // TODO review - workaround for legend symbol when series lines and legend custom position true
  1513.         if ($this->getPen()->getStyle() != DashStyle::$SOLID)         
  1514.           imageline($this->img, $p1->getX(),$p1->getY(),$p2->getX(),$p2->getY(),IMG_COLOR_STYLED);          
  1515.         else
  1516.           imageline($this->img, $p1->getX(),$p1->getY(),$p2->getX(),$p2->getY(),$c1);  
  1517.     }
  1518.  
  1519.     /**
  1520.      * Draws a Vertical Line from (X,Top) to (X,Bottom) at z depth position.
  1521.      *
  1522.      * @param x int
  1523.      * @param top int
  1524.      * @param bottom int
  1525.      * @param z int
  1526.      */
  1527.     public function verticalLine($x, $top, $bottom, $z=0) {        
  1528.         
  1529.         $p1=$this->calc3DPos($x, $top, $z);
  1530.         $p2=$this->calc3DPos($x, $bottom, $z);
  1531.  
  1532.         // Assign the pen width for the image
  1533.         imagesetthickness ( $this->img, $this->pen->getWidth());
  1534.  
  1535.         // Gets the pen color and style (dot , dashed, ...)
  1536.         $penColorStyle = $this->getPenColorStyle();
  1537.         imagesetstyle($this->img, $penColorStyle);
  1538.  
  1539.         imageline($this->img, $p1->getX(),$p1->getY(),$p2->getX(),$p2->getY(),
  1540.             IMG_COLOR_STYLED);
  1541.     }
  1542.  
  1543.     /**
  1544.     * Draw a filled gray box with thick borders and darker corners.
  1545.     *
  1546.     * @param integer top left coordinate (x)
  1547.     * @param integer top left coordinate (y)
  1548.     * @param integer bottom right coordinate (x)
  1549.     * @param integer bottom right coordinate (y)
  1550.     * @param Color edge color
  1551.     * @param Color corner color
  1552.     */
  1553.     public function outlinedBox($x1, $y1, $x2, $y2, $color0, $color1) {
  1554.         if ($this->brush->getVisible()) {
  1555.             
  1556.             if ($this->getBrush()->getGradient()->getVisible()==true) {
  1557.             
  1558.                  $colA = array($this->getBrush()->getGradient()->getStartColor()->getRed(),
  1559.                    $this->getBrush()->getGradient()->getStartColor()->getGreen(),
  1560.                    $this->getBrush()->getGradient()->getStartColor()->getBlue());   
  1561.                  $colB = array($this->getBrush()->getGradient()->getEndColor()->getRed(),
  1562.                    $this->getBrush()->getGradient()->getEndColor()->getGreen(),
  1563.                    $this->getBrush()->getGradient()->getEndColor()->getBlue());
  1564.                        
  1565.                  $penWidth=$this->getPen()->getWidth();
  1566.                  Gradient::imagecolorgradient(
  1567.                    $this->img,
  1568.                    $x1+$penWidth, $y1+$penWidth, 
  1569.                    $x2-$penWidth, $y2,
  1570.                     $colA,$colB
  1571.                  );            
  1572.             }   
  1573.             else
  1574.             {                                         
  1575.               imagefilledrectangle($this->img, $x1, $y1, $x2, $y2, $color0->getColor($this->img));
  1576.             }
  1577.             imagerectangle($this->img, $x1, $y1, $x1 + 1, $y1 + 1, $color1->getColor($this->img));
  1578.             imagerectangle($this->img, $x2 - 1, $y1, $x2, $y1 + 1, $color1->getColor($this->img));
  1579.             imagerectangle($this->img, $x1, $y2 - 1, $x1 + 1, $y2, $color1->getColor($this->img));
  1580.             imagerectangle($this->img, $x2 - 1, $y2 - 1, $x2, $y2, $color1->getColor($this->img));            
  1581.         }
  1582.     }
  1583.  
  1584.     public function paintBevel($bevel, $rect, $width, $one, $two) {
  1585.         if ($bevel == BevelStyle::$RAISED) {
  1586.             $a = new ChartPen(null,$one);
  1587.             $b = new ChartPen(null,$two);
  1588.         } else {
  1589.             $a = new ChartPen(null,$two);
  1590.             $b = new ChartPen(null,$one);
  1591.         }
  1592.  
  1593.         $tmp = $width;
  1594.         while ($tmp > 0) {
  1595.             $tmp--;
  1596.  
  1597.             $this->doBevelRect($rect, $a, $b);
  1598.             $rect->grow( -1, -1);
  1599.         }
  1600.     }
  1601.  
  1602.     /**
  1603.     * Draws a 3D Pie slice using start Angle and end Angle and donut percent.
  1604.     *
  1605.     * @param xCenter int
  1606.     * @param yCenter int
  1607.     * @param xRadius int
  1608.     * @param yRadius int
  1609.     * @param z0 int
  1610.     * @param z1 int
  1611.     * @param startAngle double
  1612.     * @param endAngle double
  1613.     * @param darkSides boolean
  1614.     * @param drawSides boolean
  1615.     * @param donutPercent int
  1616.     */
  1617. /*    public function pie($xCenter, $yCenter, $xRadius, $yRadius, $z0,
  1618.         $z1, $startAngle, $endAngle, $darkSides, $drawSides, $donutPercent=0) {
  1619.  
  1620.         if ($this->pie3D == null) {
  1621.             $this->pie3D = new Pie3D($this);
  1622.         }
  1623.         $this->pie3D->pie($xCenter, $yCenter, $xRadius, $yRadius, $z0, $z1, $startAngle,
  1624.                   $endAngle, $darkSides, $drawSides, $donutPercent);
  1625.     }
  1626. */
  1627.  
  1628.     public function pie($xCenter, $yCenter, $xOffset, $yOffset, $xRadius,
  1629.                     $yRadius, $z0, $z1, $startAngle, $endAngle,
  1630.                     $darkSides, $drawSides, $donutPercent,
  1631.                     $bevelPercent, $edgeStyle, $last/*, Shadow shadow*/)
  1632.     {
  1633.       if ($this->pie3D == null) {
  1634.             $this->pie3D = new Pie3D($this);
  1635.         }
  1636.       $this->pie3D->pie( $xCenter + $xOffset, $yCenter - $yOffset, $xRadius,  $yRadius,  $z0,  $z1,
  1637.                  $startAngle,  $endAngle,  $darkSides,  $drawSides,
  1638.                  $donutPercent,  $bevelPercent, $edgeStyle, $last);
  1639.     }
  1640.  
  1641.  
  1642.     /**
  1643.      * Draws a vertical or horizontal Pyramid with optional dark shaded sides.
  1644.      *
  1645.      * @param vertical boolean
  1646.      * @param r Rectangle
  1647.      * @param z0 int
  1648.      * @param z1 int
  1649.      * @param darkSides boolean
  1650.      */
  1651.     public function pyramidRect($vertical, $r, $z0, $z1, $darkSides) {
  1652.         $this->pyramid($vertical, $r->x, $r->y, $r->getRight(), $r->getBottom(), $z0, $z1,
  1653.                 $darkSides);
  1654.     }
  1655.  
  1656.     /**
  1657.      * Draws a vertical or horizontal Pyramid with optional dark shaded sides.
  1658.      *
  1659.      * @param vertical boolean
  1660.      * @param left int
  1661.      * @param top int
  1662.      * @param right int
  1663.      * @param bottom int
  1664.      * @param z0 int
  1665.      * @param z1 int
  1666.      * @param darkSides boolean
  1667.      */
  1668.     public function pyramid($vertical, $left, $top, $right, $bottom, $z0, $z1, $darkSides) {
  1669.  
  1670.         $oldColor = $this->brush->getSolid() ? $this->brush->getColor() : $this->getBackColor();
  1671.  
  1672.         if ($vertical) {
  1673.             if ($top != $bottom) {
  1674.                 $p0 = $this->calc3DPoint($left, $bottom, $z0);
  1675.                 $p1 = $this->calc3DPoint($right, $bottom, $z0);
  1676.                 $pTop = $this->calc3DPoint(($left + $right) / 2, $top, ($z0 + $z1) / 2);
  1677.                 $tmpArray = Array($p0, $pTop, $p1);
  1678.                 $this->polygon($tmpArray);
  1679.                 $p2 = $this->calc3DPoint($left, $bottom, $z1);
  1680.  
  1681.                 if ($top < $bottom) {
  1682.                     if ($p2->y < $pTop->y) {
  1683.                         $tmpArray = Array($p0, $pTop, $p2);
  1684.                         $this->polygon($tmpArray);                        
  1685.                     }
  1686.                 }
  1687.                 if ($darkSides) {
  1688.                     $this->internalApplyDark($oldColor, self::$DARKERCOLORQUANTITY);
  1689.                 }
  1690.  
  1691.                 $p3 = $this->calc3DPoint($right, $bottom, $z1);
  1692.                 $tmpArray = Array($p1, $pTop, $p3);
  1693.                 $this->polygon($tmpArray);                        
  1694.  
  1695.                 if (($top < $bottom) && ($p2->y < $pTop->y)) {
  1696.                     $tmpArray = Array($pTop, $p2, $p3);
  1697.                     $this->polygon($tmpArray);                        
  1698.                 }
  1699.             }
  1700.             if ($top >= $bottom) {
  1701.                 if ($darkSides) {
  1702.                     $this->internalApplyDark($oldColor, self::$DARKCOLORQUANTITY);
  1703.                 }
  1704.                 $this->rectangleY($left, $bottom, $right, $z0, $z1);
  1705.             }
  1706.         } else {
  1707.             if ($left != $right) {
  1708.                 $p0 = $this->calc3DPoint($left, $top, $z0);
  1709.                 $p1 = $this->calc3DPoint($left, $bottom, $z0);
  1710.                 $pTop = $this->calc3DPoint($right, ($top + $bottom) / 2, ($z0 + $z1) / 2);
  1711.                 $tmpArray = Array($p0, $pTop, $p1);
  1712.                 $this->polygon($tmpArray);                        
  1713.  
  1714.                 if ($darkSides) {
  1715.                     $this->internalApplyDark($oldColor, self::$DARKCOLORQUANTITY);
  1716.                 }
  1717.                 $p2 = $this->calc3DPoint($left, $top, $z1);
  1718.                 $tmpArray = Array($p0, $pTop, $p2);
  1719.                 $this->polygon($tmpArray);                        
  1720.             }
  1721.             if ($left >= $right) {
  1722.                 if ($darkSides) {
  1723.                     $this->internalApplyDark($oldColor, self::$DARKERCOLORQUANTITY);
  1724.                 }
  1725.                 $this->rectangleZ($left, $top, $bottom, $z0, $z1);
  1726.             }
  1727.         }
  1728.     }
  1729.  
  1730.     /**
  1731.      * Sets / returns the color used to fill spaces when displaying text
  1732.      * or filling with brushes of different style other than bsSolid.<br>
  1733.      * Brush.Visible must be set to true.
  1734.      *
  1735.      * @return Color 
  1736.      */
  1737.     public function getBackColor() {
  1738.         return $this->brush->getColor();
  1739.     }
  1740.  
  1741.     public function setBackColor($value) {
  1742.         $this->brush->setColor($value);
  1743.     }
  1744.     
  1745.     /**
  1746.     * Draws a pyramid with a truncated apex of variable thickness.
  1747.     *
  1748.     * @param Rectangle $r 
  1749.     * @param int $startZ 
  1750.     * @param int $endZ 
  1751.     * @param int $truncX 
  1752.     * @param int $truncZ 
  1753.     */
  1754.  
  1755.     public function pyramidTrunc($r, $startZ, $endZ, $truncX, $truncZ) {
  1756.         $p = new InternalPyramidTrunc();
  1757.         $p->r = $r;
  1758.         $p->startZ = $startZ;
  1759.         $p->endZ = $endZ;
  1760.         $p->truncX = $truncX;
  1761.         $p->truncZ = $truncZ;
  1762.         $p->draw($this);
  1763.     }
  1764.  
  1765.     /**
  1766.     * Draws a polygon (Point p1, Point p2) at Z depth offset.
  1767.     *
  1768.     * @param p1 Point
  1769.     * @param p2 Point
  1770.     * @param z0 int
  1771.     * @param z1 int
  1772.     */
  1773.     public function plane($p1, $p2, $z0, $z1) {
  1774.         $this->iPoints[0] = $this->calc3DPos($p1->getX(), $p1->getY(), $z0);
  1775.         $this->iPoints[1] = $this->calc3DPos($p2->getX(), $p2->getY(), $z0);
  1776.         $this->iPoints[2] = $this->calc3DPos($p2->getX(), $p2->getY(), $z1);
  1777.         $this->iPoints[3] = $this->calc3DPos($p1->getX(), $p1->getY(), $z1);
  1778.         $this->polygonFour();
  1779.     }
  1780.  
  1781.     /**
  1782.     * Draws a polygon (Point p1, Point p2, Point p3, Point p4) at Z depth
  1783.     * offset.
  1784.     *
  1785.     * @param p1 Point
  1786.     * @param p2 Point
  1787.     * @param p3 Point
  1788.     * @param p4 Point
  1789.     * @param z int
  1790.     */
  1791.     public function _plane($p1, $p2, $p3, $p4, $z) {
  1792.         $this->iPoints[0] = $this->calc3DPos($p1->getX(), $p1->getY(), $z);
  1793.         $this->iPoints[1] = $this->calc3DPos($p2->getX(), $p2->getY(), $z);
  1794.         $this->iPoints[2] = $this->calc3DPos($p3->getX(), $p3->getY(), $z);
  1795.         $this->iPoints[3] = $this->calc3DPos($p4->getX(), $p4->getY(), $z);
  1796.         $this->polygonFour();
  1797.     }
  1798.  
  1799.     /**
  1800.     * Draws a polygon of  four points.
  1801.     *
  1802.     * @param z0 int
  1803.     * @param z1 int
  1804.     * @param p Point[]
  1805.     */
  1806.     public function planeFour3D($z0, $z1, $p) {
  1807.         $this->iPoints[0] = $this->calc3DPoint($p[0]->x, $p[0]->y, $z0);
  1808.         $this->iPoints[1] = $this->calc3DPoint($p[1]->x, $p[1]->y, $z0);
  1809.         $this->iPoints[2] = $this->calc3DPoint($p[2]->x, $p[2]->y, $z1);
  1810.         $this->iPoints[3] = $this->calc3DPoint($p[3]->x, $p[3]->y, $z1);
  1811.         $this->polygonFour();
  1812.     }
  1813.        
  1814.     public function polygon($points) {
  1815.         if ($this->brush->getVisible()) {
  1816.                         
  1817.             $c1 = imagecolorallocatealpha($this->img, $this->getBrush()->getColor()->red,
  1818.               $this->getBrush()->getColor()->green,
  1819.               $this->getBrush()->getColor()->blue,
  1820.               $this->getBrush()->getTransparency());
  1821.  
  1822.              
  1823.             $p1 = imagecolorallocatealpha($this->img, $this->getPen()->getColor()->red,
  1824.               $this->getPen()->getColor()->green,
  1825.               $this->getPen()->getColor()->blue,
  1826.               $this->getPen()->getTransparency());
  1827.              
  1828.             $tmpArray2= Array();
  1829.  
  1830.             for ($tt=0;$tt < sizeof($points); $tt++) {
  1831.                  $tmpTeePointDouble =$points[$tt];
  1832.                  $tmpX=$tmpTeePointDouble->getX();
  1833.                  $tmpY=$tmpTeePointDouble->getY();
  1834.                  $tmpArray2[]=$tmpX;
  1835.                  $tmpArray2[]=$tmpY;
  1836.             }
  1837.                 
  1838.             if (count($tmpArray2) >= 3) {
  1839.                 imageantialias($this->img,true);
  1840.                 imagefilledpolygon($this->img, $tmpArray2, count($tmpArray2)/2, $c1);
  1841.                 imageantialias($this->img,false);
  1842.             }
  1843.             
  1844.             if ($this->getPen()->getVisible()) {
  1845.                 // Gets the pen color and style (dot , dashed, ...)
  1846.                 $penColorStyle = $this->getPenColorStyle();
  1847.                 imagesetstyle($this->img, $penColorStyle);
  1848.  
  1849.                 // Assign the pen width for the image
  1850.                 imagesetthickness ( $this->img, $this->pen->getWidth());
  1851.  
  1852.                 if (count($tmpArray2) >= 3) {
  1853.                    imageantialias($this->img,true);
  1854.                    imagepolygon($this->img, $tmpArray2, count($tmpArray2)/2, $p1);                   
  1855.                   imageantialias($this->img,false);
  1856.                 }
  1857.             }            
  1858.         }
  1859.     }
  1860.  
  1861.     /**
  1862.      * Draws a polygon with z position offset.
  1863.      *
  1864.      * @param z int
  1865.      * @param p Point[]
  1866.      */
  1867.     public function polygonZ($z, $p) {
  1868.         for ($t = 0; $t < sizeof($p); $t++) {
  1869.             $p[$t] = $this->calc3DPoint($p[$t]->getX(),$p[$t]->getY(), $z);
  1870.         }
  1871.         $this->polygon($p);
  1872.     }
  1873.  
  1874.     public function polygonPoints($p0, $p1, $p2) {
  1875.         $p = Array($p0, $p1, $p2);
  1876.         $this->polygon($p);
  1877.     }
  1878.  
  1879.  
  1880.     public function polygonFourDouble()
  1881.     {
  1882.         if ($this->brush->getVisible()) {
  1883.           $c1 = imagecolorallocatealpha($this->img, $this->getBrush()->getColor()->red,
  1884.               $this->getBrush()->getColor()->green,
  1885.               $this->getBrush()->getColor()->blue,
  1886.               $this->getBrush()->getTransparency());
  1887.  
  1888.             $p1 = imagecolorallocatealpha($this->img, $this->getPen()->getColor()->red,
  1889.               $this->getPen()->getColor()->green,
  1890.               $this->getPen()->getColor()->blue,
  1891.               $this->getPen()->getTransparency());
  1892.  
  1893.             $tmpArray2= Array();
  1894.  
  1895.             for ($tt=0;$tt < count($this->iPointDoubles); $tt++) {
  1896.                $tmpTeePoint =$this->iPointDoubles[$tt];
  1897.                  $tmpX=$tmpTeePoint->getX();
  1898.                  $tmpY=$tmpTeePoint->getY();
  1899.                  $tmpArray2[]=$tmpX;
  1900.                  $tmpArray2[]=$tmpY;
  1901.             }
  1902.  
  1903.             if (count($tmpArray2) >= 3) {
  1904.                 imageantialias($this->img,true);
  1905.                 imagefilledpolygon($this->img, $tmpArray2, count($tmpArray2)/2, $c1);
  1906.                 imageantialias($this->img,false);
  1907.             }
  1908.         }
  1909.  
  1910.         if ($this->getPen()->getVisible()) {
  1911.           // Gets the pen color and style (dot , dashed, ...)
  1912.           $penColorStyle = $this->getPenColorStyle();
  1913.           imagesetstyle($this->img, $penColorStyle);
  1914.  
  1915.           // Assign the pen width for the image
  1916.           imagesetthickness ( $this->img, $this->pen->getWidth());
  1917.  
  1918.             if (count($tmpArray2) >= 3) {
  1919.                 imageantialias($this->img,true);
  1920.                 imagepolygon($this->img, $tmpArray2, count($tmpArray2)/2, $p1);
  1921.                 imageantialias($this->img,false);
  1922.             }
  1923.         }
  1924.     }
  1925.  
  1926.     private function polygonFour() {
  1927.         $tmpArray2= Array();
  1928.         if ($this->brush->getVisible()) {
  1929.  
  1930.           $c1 = imagecolorallocatealpha($this->img, $this->getBrush()->getColor()->red,
  1931.               $this->getBrush()->getColor()->green,
  1932.               $this->getBrush()->getColor()->blue,
  1933.               $this->getBrush()->getTransparency());
  1934.  
  1935.             $p1 = imagecolorallocatealpha($this->img, $this->getPen()->getColor()->red,
  1936.               $this->getPen()->getColor()->green,
  1937.               $this->getPen()->getColor()->blue,
  1938.               $this->getPen()->getTransparency());              
  1939.  
  1940.  
  1941.             for ($tt=0;$tt < count($this->iPoints); $tt++) {
  1942.                  $tmpTeePoint =$this->iPoints[$tt];
  1943.                  $tmpX=$tmpTeePoint->getX();
  1944.                  $tmpY=$tmpTeePoint->getY();
  1945.                  $tmpArray2[]=$tmpX;
  1946.                  $tmpArray2[]=$tmpY;
  1947.             }
  1948.  
  1949.             if (count($tmpArray2) >= 3) {
  1950.                 imageantialias($this->img,true);
  1951.                 imagefilledpolygon($this->img, $tmpArray2, count($tmpArray2)/2, $c1);
  1952.                 imageantialias($this->img,false);
  1953.             }
  1954.         }
  1955.  
  1956.         if ($this->getPen()->getVisible()) {
  1957.           // Gets the pen color and style (dot , dashed, ...)
  1958.           $penColorStyle = $this->getPenColorStyle();
  1959.           imagesetstyle($this->img, $penColorStyle);
  1960.  
  1961.           // Assign the pen width for the image
  1962.           imagesetthickness ( $this->img, $this->pen->getWidth());
  1963.  
  1964.             if (count($tmpArray2) >= 3) {
  1965.                 imageantialias($this->img,true);
  1966.                 imagepolygon($this->img, $tmpArray2, count($tmpArray2)/2, $p1);
  1967.                 imageantialias($this->img,false);
  1968.             }
  1969.         }
  1970.     }
  1971.  
  1972.     /**
  1973.      * Draws a series of line segments to join point array p at z displacement.
  1974.      *
  1975.      * @param z int
  1976.      * @param p Point[]
  1977.      */
  1978.     public function polyLine($z, $p) {
  1979.         $l = sizeof($p);
  1980.         $tmpP = Array(); //new Point[l];
  1981.         for ($t = 0; $t < $l; $t++) {
  1982.             $tmpP[$t] = $this->calc3DPoint($p[$t]->getX(),$p[$t]->getY(), $z);
  1983.         }
  1984.         for ($t = 1; $t < $l; $t++) {
  1985.             $this->line($tmpP[$t - 1]->getX(),$tmpP[$t - 1]->getY(),
  1986.                 $tmpP[$t]->getX(),$tmpP[$t]->getY());
  1987.         }
  1988.     }
  1989.  
  1990.     /**
  1991.     * Print text.
  1992.     *
  1993.     * @param Image GD image
  1994.     * @param integer text coordinate (x)
  1995.     * @param integer text coordinate (y)
  1996.     * @param Color text color
  1997.     * @param string text value
  1998.     * @param string font file name
  1999.     * @param bitfield text alignment
  2000.     */
  2001.     public function printText($img, $px, $py, $text, $align = -1) {
  2002.  
  2003.         $font=$this->getFont();
  2004.         $color = $font->getBrush()->getColor();
  2005.  
  2006.         $fontFileName = $font->getName();
  2007.  
  2008.         if ($align==-1) {
  2009.            $align = $this->getTextAlign();
  2010.         }
  2011.  
  2012.         $fontSize = $font->getFontSize();
  2013.         $lineSpacing = 1;
  2014.  
  2015.         $textWidth =  $this->textWidth($text); //  $lrx - $llx;
  2016.         $textHeight = $this->textHeight($text); //  $fontSize; // $lry - $ury;
  2017.         $angle = 0;
  2018.  
  2019.         if (in_array(StringAlignment::$HORIZONTAL_CENTER_ALIGN, $align)) {
  2020.             $px -= $textWidth / 2;
  2021.         }
  2022.         else
  2023.         if (in_array (StringAlignment::$HORIZONTAL_RIGHT_ALIGN, $align)) {
  2024.             $px -= $textWidth;
  2025.         }
  2026.  
  2027.         if (in_array (StringAlignment::$VERTICAL_CENTER_ALIGN, $align)) {
  2028.             $py += $textHeight - 3;
  2029.         }
  2030.  
  2031.         /*if (in_array (StringAlignment::$VERTICAL_TOP_ALIGN, $align)) {
  2032.             $py += $textHeight;
  2033.         }*/
  2034.         else
  2035.         if (in_array (StringAlignment::$VERTICAL_BOTTOM_ALIGN, $align)) {
  2036.             $py += $textHeight + 3;
  2037.         }
  2038.  
  2039.         imagettftext($img, $fontSize, $angle, $px, $py, $color->getColor($img),
  2040.             $fontFileName, $text);
  2041.     }
  2042.  
  2043.     /**
  2044.     * Print text centered horizontally on the image.
  2045.     *
  2046.     * @param Image GD image
  2047.     * @param integer text coordinate (y)
  2048.     * @param Color text color
  2049.     * @param string text value
  2050.     * @param string font file name
  2051.     */
  2052.     public function printCentered($img, $py, $color, $text, $fontFileName) {
  2053.           $tmpAlign = Array(StringAlignment::$HORIZONTAL_CENTER_ALIGN,StringAlignment::$VERTICAL_CENTER_ALIGN);
  2054.           $this->printText($img, imagesx($img) / 2, $py, $color, $text, $fontFileName,
  2055.               $tmpAlign);
  2056.     }
  2057.  
  2058.     /**
  2059.     * Print text in diagonal.
  2060.     *
  2061.     * @param Image GD image
  2062.     * @param integer text coordinate (x)
  2063.     * @param integer text coordinate (y)
  2064.     * @param Color text color
  2065.     * @param string text value
  2066.     */
  2067.     public function printDiagonal($img, $px, $py, $text, $angle) {
  2068.  
  2069.         $font=$this->getFont();
  2070.         $fontSize = $font->getFontSize();
  2071.         $fontFileName = $font->getName();
  2072.         $color = $font->getBrush()->getColor(); //  $this->textColor;
  2073.         $lineSpacing = 1;
  2074.  
  2075.         list ($lx, $ly, $rx, $ry) = imageftbbox($fontSize, 0, $fontFileName,
  2076.             strtoupper($text), array("linespacing" => $lineSpacing));
  2077.  
  2078.         $textWidth = $rx - $lx;
  2079.  
  2080.         imagettftext($img, $fontSize, $angle, $px, $py, $color->getColor($img),
  2081.             $fontFileName, $text);
  2082.     }
  2083.  
  2084.     /**
  2085.      * Internal use. Calculates the projection co-ordinates for rectangle
  2086.      * Bounds.<br>
  2087.      *
  2088.      * @param maxDepth int is the max shape depth
  2089.      * @param r Rectangle is the projected shape rectangle
  2090.      */
  2091.     public function projection($maxDepth, $r) {
  2092.         $this->xCenter = ($r->x + ($r->width * 0.5) + $this->getRotationCenter()->x);
  2093.         $this->yCenter = ($r->y + ($r->height * 0.5) + $this->getRotationCenter()->y);
  2094.         $this->zCenter = (($maxDepth * 0.5) + $this->getRotationCenter()->z);
  2095.         $this->xCenterOffset = $this->xCenter + $this->aspect->getHorizOffset();
  2096.         $this->yCenterOffset = $this->yCenter + $this->aspect->getVertOffset();
  2097.  
  2098.         $this->calcPerspective($r);
  2099.     }
  2100.  
  2101.     public function rectangle($rect) {
  2102.         if ($this->getBrush()->getVisible()) {
  2103.             
  2104.             $c1 = imagecolorallocatealpha($this->img, $this->getBrush()->getColor()->red,
  2105.               $this->getBrush()->getColor()->green,
  2106.               $this->getBrush()->getColor()->blue,
  2107.               $this->getBrush()->getTransparency());
  2108.              
  2109.             if ($this->getBrush()->getGradient()->getVisible()==true) {
  2110.             
  2111.                  $colA = array($this->getBrush()->getGradient()->getStartColor()->getRed(),
  2112.                    $this->getBrush()->getGradient()->getStartColor()->getGreen(),
  2113.                    $this->getBrush()->getGradient()->getStartColor()->getBlue());   
  2114.                  $colB = array($this->getBrush()->getGradient()->getEndColor()->getRed(),
  2115.                    $this->getBrush()->getGradient()->getEndColor()->getGreen(),
  2116.                    $this->getBrush()->getGradient()->getEndColor()->getBlue());
  2117.                        
  2118.                  $penWidth=$this->getPen()->getWidth();
  2119.                  Gradient::imagecolorgradient(
  2120.                    $this->img,
  2121.                    $rect->getX()+$penWidth, $rect->getY()+$penWidth, 
  2122.                    $rect->getRight()-$penWidth, $rect->getHeight()-$penWidth+$rect->getY(),
  2123.                    $colA,
  2124.                    $colB
  2125.                  );            
  2126.             }   
  2127.             else
  2128.             {                             
  2129.               imagefilledrectangle($this->img, $rect->x, $rect->y, $rect->getRight(),
  2130.                 $rect->getBottom(), $c1);
  2131.             }
  2132.         }
  2133.  
  2134.         /* TODO Gradient - post the code into the shape..
  2135.         if ($this->getBrush()->getGradient()->getVisible()==true) {
  2136.             $this->getBrush()->getGradient()->fill($this->img,
  2137.             $this->getBrush()->getGradient()->getDirection(),
  2138.             $this->getBrush()->getGradient()->getStartColor(),
  2139.             $this->getBrush()->getGradient()->getEndColor());            
  2140.         }   
  2141.         */
  2142.  
  2143.         if ($this->getPen()->getVisible()) {
  2144.           // Gets the pen color and style (dot , dashed, ...)
  2145.           $penColorStyle = $this->getPenColorStyle();
  2146.           imagesetstyle($this->img, $penColorStyle);
  2147.  
  2148.           // Assign the pen width for the image
  2149.           imagesetthickness ( $this->img, $this->pen->getWidth());
  2150.           imagerectangle($this->img, $rect->x, $rect->y, $rect->getRight(),
  2151.               $rect->getBottom(), IMG_COLOR_STYLED); 
  2152.           }        
  2153.     }
  2154.  
  2155.     public function _rectangle($x, $y, $width, $height) {
  2156.         $this->rectangle(new Rectangle($x,$y,$width.$height));
  2157.     }
  2158.  
  2159.     /**
  2160.      * Horizontal Rectangle from Left to Right, from Z0 to Z1 position,
  2161.      * at Top Y.<br>
  2162.      *
  2163.      * @param left int
  2164.      * @param top int
  2165.      * @param bottom int
  2166.      * @param z0 int
  2167.      * @param z1 int
  2168.      */
  2169.     public function rectangleZ($left, $top, $bottom, $z0, $z1) {
  2170.         $this->iPoints[0] = $this->calc3DPos($left, $top, $z0);
  2171.         $this->iPoints[1] = $this->calc3DPos($left, $top, $z1);
  2172.         $this->iPoints[2] = $this->calc3DPos($left, $bottom, $z1);
  2173.         $this->iPoints[3] = $this->calc3DPos($left, $bottom, $z0);
  2174.         $this->polygonFour();
  2175.     }
  2176.  
  2177.     public function rectangleWithZ($r, $z) {
  2178.         $this->iPoints[0] = $this->calc3DPos($r->x, $r->y, $z);
  2179.         $this->iPoints[1] = $this->calc3DPos($r->getRight(), $r->y, $z);
  2180.         $this->iPoints[2] = $this->calc3DPos($r->getRight(), $r->getBottom(), $z);
  2181.         $this->iPoints[3] = $this->calc3DPos($r->x, $r->getBottom(), $z);
  2182.         $this->polygonFour();
  2183.     }
  2184.  
  2185.     /**
  2186.      * Horizontal Rectangle from Left to Right, from Z0 to Z1 position,
  2187.      * at Top Y.<br>
  2188.      *
  2189.      * @param left int
  2190.      * @param top int
  2191.      * @param right int
  2192.      * @param z0 int
  2193.      * @param z1 int
  2194.      */
  2195.     public function rectangleY($left, $top, $right, $z0, $z1) {
  2196.         $this->iPoints[0] = $this->calc3DPos($left, $top, $z0);
  2197.         $this->iPoints[1] = $this->calc3DPos($right, $top, $z0);
  2198.         $this->iPoints[2] = $this->calc3DPos($right, $top, $z1);
  2199.         $this->iPoints[3] = $this->calc3DPos($left, $top, $z1);
  2200.         $this->polygonFour();
  2201.     }
  2202.  
  2203.     // With this function you will draw rounded corners rectangles with transparent colors.
  2204.     // Empty (not filled) figures are allowed too!!
  2205.  
  2206.     function roundrectangle($x1, $y1, $x2, $y2, $radius, $filled=1) {
  2207.  
  2208.       $color = imagecolorallocate($this->img, $this->getBrush()->getColor()->red,
  2209.             $this->getBrush()->getColor()->green,
  2210.             $this->getBrush()->getColor()->blue);
  2211.  
  2212.       if ($filled==1){
  2213.         if ($this->getBrush()->getVisible()) {
  2214.           imagefilledrectangle($this->img, $x1+$radius, $y1, $x2-$radius, $y2, $color);
  2215.           imagefilledrectangle($this->img, $x1, $y1+$radius, $x1+$radius-1, $y2-$radius, $color);
  2216.           imagefilledrectangle($this->img, $x2-$radius+1, $y1+$radius, $x2, $y2-$radius, $color);
  2217.  
  2218.           imagefilledarc($this->img,$x1+$radius, $y1+$radius, $radius*2, $radius*2, 180 , 270, $color, IMG_ARC_PIE);
  2219.           imagefilledarc($this->img,$x2-$radius, $y1+$radius, $radius*2, $radius*2, 270 , 360, $color, IMG_ARC_PIE);
  2220.           imagefilledarc($this->img,$x1+$radius, $y2-$radius, $radius*2, $radius*2, 90 , 180, $color, IMG_ARC_PIE);
  2221.           imagefilledarc($this->img,$x2-$radius, $y2-$radius, $radius*2, $radius*2, 360 , 90, $color, IMG_ARC_PIE);
  2222.         }
  2223.       }else{
  2224.         imageline($this->img, $x1+$radius, $y1, $x2-$radius, $y1, $color);
  2225.         imageline($this->img, $x1+$radius, $y2, $x2-$radius, $y2, $color);
  2226.         imageline($this->img, $x1, $y1+$radius, $x1, $y2-$radius, $color);
  2227.         imageline($this->img, $x2, $y1+$radius, $x2, $y2-$radius, $color);
  2228.  
  2229.         imagearc($this->img,$x1+$radius, $y1+$radius, $radius*2, $radius*2, 180 , 270, $color);
  2230.         imagearc($this->img,$x2-$radius, $y1+$radius, $radius*2, $radius*2, 270 , 360, $color);
  2231.         imagearc($this->img,$x1+$radius, $y2-$radius, $radius*2, $radius*2, 90 , 180, $color);
  2232.         imagearc($this->img,$x2-$radius, $y2-$radius, $radius*2, $radius*2, 360 , 90, $color);
  2233.       }
  2234.     }
  2235.  
  2236.     function drawRoundedBorders($shapeBorders,$backcolor,$forecolor) {        
  2237.  
  2238.             $sourcefile_width=imagesx($this->img);
  2239.             $sourcefile_height=imagesy($this->img);
  2240.             $background = imagecreatetruecolor($sourcefile_width,$sourcefile_height);
  2241.  
  2242.             if ($backcolor==null) {
  2243.                 $backcolor = new Color(0,0,0,127);  //  transparent
  2244.             }
  2245.             if ($forecolor==null) {
  2246.                 $forecolor = new Color(0,0,0,127);  // transparent
  2247.             }
  2248.  
  2249.             if ($shapeBorders->getTopLeft()->getBorderRound() > 0) {
  2250.  
  2251.                 $endsize=$shapeBorders->getTopLeft()->getBorderRound();;
  2252.                 $startsize=$endsize*3-1;
  2253.                 $arcsize=$startsize*2+1;
  2254.  
  2255.                 imagecopymerge($background, $this->img, 0, 0, 0, 0, $sourcefile_width, $sourcefile_height, 100);
  2256.                 $startx=$sourcefile_width*2-1;
  2257.                 $starty=$sourcefile_height*2-1;
  2258.                 $im_temp = imagecreatetruecolor($startx,$starty);
  2259.                 imagecopyresampled($im_temp, $background, 0, 0, 0, 0, $startx, $starty, $sourcefile_width, $sourcefile_height);
  2260.                 $bg = imagecolorallocate($im_temp,$backcolor->red,$backcolor->green, $backcolor->blue);
  2261.                 $fg = imagecolorallocate($im_temp,$forecolor->red,$forecolor->green, $forecolor->blue);
  2262.  
  2263.                 imagearc($im_temp, $startsize, $startsize, $arcsize, $arcsize, 180,270,$fg);
  2264.                 imagefilltoborder($im_temp,0,0,$fg,$bg);
  2265.                 imagecopyresampled($this->img, $im_temp, 0, 0, 0, 0, $sourcefile_width,$sourcefile_height,$startx, $starty);
  2266.                 imagedestroy($im_temp);
  2267.             }
  2268.  
  2269.             if ($shapeBorders->getBottomLeft()->getBorderRound() > 0) {
  2270.  
  2271.                 $endsize=$shapeBorders->getBottomLeft()->getBorderRound();;
  2272.                 $startsize=$endsize*3-1;
  2273.                 $arcsize=$startsize*2+1;
  2274.  
  2275.                 imagecopymerge($background, $this->img, 0, 0, 0, 0, $sourcefile_width, $sourcefile_height, 100);
  2276.                 $startx=$sourcefile_width*2-1;
  2277.                 $starty=$sourcefile_height*2-1;
  2278.                 $im_temp = imagecreatetruecolor($startx,$starty);
  2279.                 imagecopyresampled($im_temp, $background, 0, 0, 0, 0, $startx, $starty, $sourcefile_width, $sourcefile_height);
  2280.                 $bg = imagecolorallocate($im_temp,$backcolor->red,$backcolor->green, $backcolor->blue);
  2281.                 $fg = imagecolorallocate($im_temp,$forecolor->red,$forecolor->green, $forecolor->blue);
  2282.  
  2283.                 imagearc($im_temp, $startsize, $starty-$startsize,$arcsize, $arcsize, 90,180,$fg);
  2284.                 imagefilltoborder($im_temp,0,$starty,$fg,$bg);
  2285.                 imagecopyresampled($this->img, $im_temp, 0, 0, 0, 0, $sourcefile_width,$sourcefile_height,$startx, $starty);
  2286.                 imagedestroy($im_temp);
  2287.             }
  2288.  
  2289.             if ($shapeBorders->getTopRight()->getBorderRound() > 0) {
  2290.  
  2291.                 $endsize=$shapeBorders->getTopRight()->getBorderRound();;
  2292.                 $startsize=$endsize*3-1;
  2293.                 $arcsize=$startsize*2+1;
  2294.  
  2295.                 imagecopymerge($background, $this->img, 0, 0, 0, 0, $sourcefile_width, $sourcefile_height, 100);
  2296.                 $startx=$sourcefile_width*2-1;
  2297.                 $starty=$sourcefile_height*2-1;
  2298.                 $im_temp = imagecreatetruecolor($startx,$starty);
  2299.                 imagecopyresampled($im_temp, $background, 0, 0, 0, 0, $startx, $starty, $sourcefile_width, $sourcefile_height);
  2300.                 $bg = imagecolorallocate($im_temp,$backcolor->red,$backcolor->green, $backcolor->blue);
  2301.                 $fg = imagecolorallocate($im_temp,$forecolor->red,$forecolor->green, $forecolor->blue);
  2302.  
  2303.                 imagearc($im_temp, $startx-$startsize, $startsize,$arcsize, $arcsize, 270,360,$fg);
  2304.                 imagefilltoborder($im_temp,$startx,0,$fg,$bg);
  2305.                 imagecopyresampled($this->img, $im_temp, 0, 0, 0, 0, $sourcefile_width,$sourcefile_height,$startx, $starty);
  2306.                 imagedestroy($im_temp);
  2307.             }
  2308.  
  2309.             if ($shapeBorders->getBottomRight()->getBorderRound() > 0) {
  2310.  
  2311.                 $endsize=$shapeBorders->getBottomRight()->getBorderRound();;
  2312.                 $startsize=$endsize*3-1;
  2313.                 $arcsize=$startsize*2+1;
  2314.  
  2315.                 imagecopymerge($background, $this->img, 0, 0, 0, 0, $sourcefile_width, $sourcefile_height, 100);
  2316.                 $startx=$sourcefile_width*2-1;
  2317.                 $starty=$sourcefile_height*2-1;
  2318.                 $im_temp = imagecreatetruecolor($startx,$starty);
  2319.                 imagecopyresampled($im_temp, $background, 0, 0, 0, 0, $startx, $starty, $sourcefile_width, $sourcefile_height);
  2320.                 $bg = imagecolorallocate($im_temp,$backcolor->red,$backcolor->green, $backcolor->blue);
  2321.                 $fg = imagecolorallocate($im_temp,$forecolor->red,$forecolor->green, $forecolor->blue);
  2322.  
  2323.                 imagearc($im_temp, $startx-$startsize, $starty-$startsize,$arcsize, $arcsize, 0,90,$fg);
  2324.                 imagefilltoborder($im_temp,$startx,$starty,$fg,$bg);
  2325.                 imagecopyresampled($this->img, $im_temp, 0, 0, 0, 0, $sourcefile_width,$sourcefile_height,$startx, $starty);
  2326.                 imagedestroy($im_temp);
  2327.             }
  2328.  
  2329.             imagedestroy($background);
  2330.     }
  2331.  
  2332.     /**
  2333.      * Draws a triangle (point p0, pointp1, pointp2) at Z position.
  2334.      *
  2335.      * @param p0 Point
  2336.      * @param p1 Point
  2337.      * @param p2 Point
  2338.      * @param z int
  2339.      */
  2340.     public function triangle($p0, $p1, $p2, $z=0) {
  2341.         $p0 = $this->calc3DPoint($p0->getX(), $p0->getY(), $z);
  2342.         $p1 = $this->calc3DPoint($p1->getX(), $p1->getY(), $z);
  2343.         $p2 = $this->calc3DPoint($p2->getX(), $p2->getY(), $z);
  2344.         $this->polygonPoints($p0, $p1, $p2);
  2345.     }
  2346.     
  2347.     public function arc($x1,$y1,$x2,$y2,$startAngle, $sweepAngle,$filled=0) {
  2348.       $color = imagecolorallocate($this->img, $this->getBrush()->getColor()->red,
  2349.             $this->getBrush()->getColor()->green,
  2350.             $this->getBrush()->getColor()->blue);
  2351.  
  2352.             
  2353.       if ($filled==1){
  2354.         if ($this->getBrush()->getVisible()) {
  2355.           imagefilledarc($this->img,$x1, $y1, $x2-$x1, $y2-$y1, $startAngle , $endAngle, $color, IMG_ARC_PIE);
  2356.         }
  2357.       }else{
  2358.         imagearc($this->img,$x1, $y1, $x2-$x1, $y2-$y1, $startAngle, $endAngle, $color);
  2359.       }
  2360.     }
  2361.  
  2362.     /**
  2363.      * Draws a rotated text String at the specified x,y and z coordinates with
  2364.      * the RotDegree rotation angle.<br>
  2365.      * RotDegree values must be between 0 and 360.<br>
  2366.      * The string is drawn on the Chart Drawing Canvas.
  2367.      *
  2368.      * @param x int
  2369.      * @param y int
  2370.      * @param z int
  2371.      * @param text String
  2372.      * @param rotDegree double
  2373.      */
  2374.     public function rotateLabel($x, $y, $z, $text, $rotDegree) {
  2375.         // TODO - z param is not considred at the moment
  2376.         $this->printDiagonal($this->img,$x,$y,$text,$rotDegree);
  2377.     }
  2378.  
  2379.     /**
  2380.      * Draws a rotated text String at the specified Point x,y coordinates with
  2381.      * the RotDegree rotation angle.<br>
  2382.      * RotDegree values must be between 0 and 360.<br>
  2383.      * The string is drawn on the Chart Drawing Canvas.
  2384.      *
  2385.      * @param p Point
  2386.      * @param text String
  2387.      * @param rotDegree double
  2388.      */
  2389.     public function _rotateLabel($p, $text, $rotDegree) {
  2390.         $this->rotateLabel($p->getX(), $p->getY(), $text, $rotDegree);
  2391.     }
  2392.  
  2393.     public function rotateRectangle($r, $angle) {
  2394.          $tmpCenter = $r->center();
  2395.          $tmpMathUtils = new MathUtils();
  2396.          $tmp = $angle * MathUtils::getPiStep();
  2397.          $tmpSin = sin($tmp);
  2398.          $tmpCos = cos($tmp);
  2399.  
  2400.          $tmpRect = $r;
  2401.          $tmpRect->offset( -$tmpCenter->x, -$tmpCenter->y);
  2402.  
  2403.          $result = Array();
  2404.          $result[0] = $this->rotatePoint($tmpRect->x, $tmpRect->y, $tmpCenter, $tmpCos, $tmpSin);
  2405.          $result[1] = $this->rotatePoint($tmpRect->getRight(), $tmpRect->y, $tmpCenter,
  2406.                                 $tmpCos,
  2407.                                 $tmpSin);
  2408.          $result[2] = $this->rotatePoint($tmpRect->getRight(), $tmpRect->getBottom(),
  2409.                                 $tmpCenter,
  2410.                                 $tmpCos, $tmpSin);
  2411.          $result[3] = $this->rotatePoint($tmpRect->x, $tmpRect->getBottom(), $tmpCenter,
  2412.                                 $tmpCos,
  2413.                                 $tmpSin);
  2414.  
  2415.         return $result;
  2416.     }
  2417.  
  2418.     private function rotatePoint($ax, $ay, $tmpCenter, $tmpCos, $tmpSin) {
  2419.          $p = new TeePoint();
  2420.          $p->x = $tmpCenter->x + (int)($ax * $tmpCos + $ay * $tmpSin);
  2421.          $p->y = $tmpCenter->y + (int)( -$ax * $tmpSin + $ay * $tmpCos);
  2422.  
  2423.          return $p;
  2424.     }
  2425.  
  2426.     public function sliceArray($source, $length) {
  2427.         $result = Array();
  2428.         for ($t = 0; $t < $length; $t++) {
  2429.             $result[$t] = $source[$t];
  2430.         }
  2431.         return $result;
  2432.     }
  2433.  
  2434.     /**
  2435.      * Displays the 2D non-rotated label at the specified X Y screen
  2436.      * coordinates.<br>
  2437.      * Text is outputted to the correct internal drawing Graphics2D. <br>
  2438.      * The X and Y coordinates must be valid and fit inside the Chart
  2439.      * rectangle. It uses the current drawing Font attributes. <br>
  2440.      * Writes text at the named x and y co-ordinates.
  2441.      *
  2442.      * @param x int
  2443.      * @param y int
  2444.      * @param z int
  2445.      * @param text String
  2446.      */
  2447.     public function textOut($x, $y, $z, $text, $align=-1) {
  2448.         $f = $this->getFont();
  2449.  
  2450.         if ($z <> 0) {
  2451.             $p = $this->calc3DPos($x, $y, $z);
  2452.  
  2453.             /* TODO style of font
  2454.             if (($this->iZoomText) && ($this->iZoomFactor != -1)) {
  2455.                 (double) $old = $this->font->getDrawingFont()->getSize();
  2456.                 (int) $tmp = (int) max(1, $this->iZoomFactor * $old);
  2457.                 if ($old != $tmp) {
  2458.                     $this->font->setSize($tmp);
  2459.                 }
  2460.             }
  2461.             */
  2462.  
  2463.             $x = $p->getX();
  2464.             $y = $p->getY();
  2465.         }
  2466.  
  2467.         /* TODO text shadow
  2468.         if ($f->shouldDrawShadow()) {
  2469.             $s = $f->getShadow();
  2470.             $this->drawString(x + s.getWidth(), y + s.getHeight(), text, s.getBrush());
  2471.         }
  2472.         */
  2473.         if ($align==-1) {
  2474.            $align = $this->getTextAlign();
  2475.         }
  2476.  
  2477.         $this->printText($this->img, $x, $y, $text, $align); //, $f->getBrush());
  2478.     }
  2479.  
  2480.     /**
  2481.      * Returns the vertical text size in pixels of ChartFont f.
  2482.      *
  2483.      * @param f ChartFont
  2484.      * @param text String
  2485.      * @return int Height in pixels of ChartFont f.
  2486.      */
  2487.     public function _textHeight($f, $text) {
  2488.         return imagefontheight($f->getFontSize());
  2489.     }
  2490.  
  2491.     /**
  2492.      * Returns the horizontal text size in pixels of ChartFont f.
  2493.      *
  2494.      * @param f ChartFont
  2495.      * @param text String
  2496.      * @return int Width in pixels of ChartFont f.
  2497.      */
  2498.     public function textWidth($text, $f=null) {
  2499.        if ($f==null)
  2500.            $f=$this->font;
  2501.  
  2502.        $lineSpacing = 1;
  2503.  
  2504.        list ($llx, $lly, $lrx, $lry, $urx, $ury, $ulx, $uly) = imageftbbox($f->getFontSize(),
  2505.                0, $f->getName(), strtoupper($text), array("linespacing" => $lineSpacing));
  2506.  
  2507.        $width = $lrx - $llx;
  2508.  
  2509.        return round($width);
  2510.     }
  2511.  
  2512.     /**
  2513.      * Returns the vertical size in pixels of the text String.
  2514.      *
  2515.      * @param text String
  2516.      * @return int Height in pixels of the text String.
  2517.      */
  2518.     public function textHeight($text) {
  2519.         return $this->_textHeight($this->font, $text);
  2520.     }
  2521.  
  2522.     /**
  2523.      * Calculates the boundary points of the convex hull of a set of 2D xy
  2524.      * points.&nbsp;Original
  2525.      *
  2526.      * @param p Point[]
  2527.      * @return int 
  2528.      */
  2529.     public function convexHull($p) {
  2530.         if (sizeof($p) == 3) {
  2531.             return 3;
  2532.         } else if (sizeof($p) < 3) {
  2533.             return 0;
  2534.         } else {
  2535.             // find pivot point, which is known to be on the hull
  2536.             // point with lowest y - if there are multiple, point with highest x
  2537.             $lminY = 10000000;
  2538.             $lmaxX = 10000000;
  2539.             $lpivotIndex = 0;
  2540.  
  2541.             $lbound = 0;
  2542.  
  2543.             $ubound = sizeof($p) - 1;
  2544.             $tmpubound = $ubound - 1;
  2545.  
  2546.             for ($lIndex = $lbound; $lIndex <= $ubound; $lIndex++) {
  2547.                 if ($p[$lIndex]->getY() == $lminY) {
  2548.                     if ($p[$lIndex]->getX() > $lmaxX) {
  2549.                         $lmaxX = $p[$lIndex]->getX();
  2550.                         $lpivotIndex = $lIndex;
  2551.                     }
  2552.                 } else if ($p[$lIndex]->getY() < $lminY) {
  2553.                     $lminY = $p[$lIndex]->getY();
  2554.                     $lmaxX = $p[$lIndex]->getX();
  2555.                     $lpivotIndex = $lIndex;
  2556.                 }
  2557.             }
  2558.  
  2559.             // put pivot into seperate variable and remove from array
  2560.             $lPivot = $p[$lpivotIndex];
  2561.             $p[$lpivotIndex] = $p[$ubound];
  2562.  
  2563.             // calculate angle to pivot for each point in the array
  2564.             // quicker to calculate dot product of point with a horizontal comparison vector
  2565.             $langles = Array();  // Array of doubles
  2566.             //double[] langles = new double[tmpubound + 1];
  2567.  
  2568.             for ($lindex = 0; $lindex <= $tmpubound; $lindex++) {
  2569.                 $lvx = $lPivot->getX() - $p[$lindex]->getX();
  2570.                 $lvy = $lPivot->getY() - $p[$lindex]->getY();
  2571.  
  2572.                 // reduce to a unit-vector - length 1
  2573.                 $tmp = sqrt($lvx * $lvx + $lvy * $lvy);
  2574.                 $langles[$lindex] = ($tmp == 0) ? 0.0 : $lvx / $tmp;
  2575.             }
  2576.  
  2577.             // sort the points by angle
  2578.             self::quickSortAngle($p, $langles, 0, $tmpubound);
  2579.  
  2580.             // step through array to remove points that are not part of the convex hull
  2581.             $t = 1;
  2582.             $lrightturn = true;
  2583.  
  2584.             do {
  2585.                 // assign points behind and infront of current point
  2586.                 if ($t == 0) {
  2587.                     $lrightturn = true;
  2588.                 } else {
  2589.                     $lBehind = $p[$t - 1];
  2590.                     $lInFront = ($t == $tmpubound) ? $lPivot : $p[$t + 1];
  2591.  
  2592.                     // work out if we are making a right or left turn using vector product
  2593.                     $lrightturn = (($lBehind->getX() - $p[$t]->getX()) * ($lInFront->getY() - $p[$t]->getY())) -
  2594.                                  (($lInFront->getX() - $p[$t]->getX()) * ($lBehind->getY() - $p[$t]->getY())) < 0;
  2595.                 }
  2596.  
  2597.                 if ($lrightturn) {
  2598.                     $t++;
  2599.                 } else {
  2600.                     $tmphigh = $tmpubound;
  2601.                     // remove point from convex hull
  2602.                     if ($t != $tmphigh) {
  2603.                         for ($i = $t; $i < $tmphigh; $i++) {
  2604.                             $p[$i] = $p[$i + 1];
  2605.                         }
  2606.                     }
  2607.                     $tmpubound = $tmphigh - 1;
  2608.                     $t--; // backtrack to previous point
  2609.                 }
  2610.             } while ($t != $tmpubound);
  2611.  
  2612.             // add pivot back into points array
  2613.             $tmpubound++;
  2614.             $p[$tmpubound] = $lPivot;
  2615.             return $tmpubound + 1;
  2616.         }
  2617.     }
  2618.  
  2619.     /**
  2620.      * Sort an array of points by angles.
  2621.      *
  2622.      * @param p Point[]
  2623.      * @param angles double[]
  2624.      * @param low int
  2625.      * @param high int
  2626.      */
  2627.     static private function quickSortAngle($p, $angles, $low, $high) {
  2628.         $lo = $low;
  2629.         $hi = $high;
  2630.         $midangle = $angles[($lo + $hi) / 2];
  2631.  
  2632.         do {
  2633.             while ($angles[$lo] < $midangle) {
  2634.                 $lo++;
  2635.             } while ($angles[$hi] > $midangle) {
  2636.                 $hi--;
  2637.             }
  2638.             if ($lo <= $hi) {
  2639.                 // swap points
  2640.                 $tpoint = $p[$lo];
  2641.                 $p[$lo] = $p[$hi];
  2642.                 $p[$hi] = $tpoint;
  2643.                 // swap angles
  2644.                 $tangle = $angles[$lo];
  2645.                 $angles[$lo] = $angles[$hi];
  2646.                 $angles[$hi] = $tangle;
  2647.                 $lo++;
  2648.                 $hi--;
  2649.             }
  2650.         } while ($lo <= $hi);
  2651.  
  2652.         // perform quicksorts on subsections
  2653.         if ($hi > $low) {
  2654.             self::quickSortAngle($p, $angles, $low, $hi);
  2655.         }
  2656.         if ($lo < $high) {
  2657.             self::quickSortAngle($p, $angles, $lo, $high);
  2658.         }
  2659.     }
  2660.  
  2661.  
  2662.     /**************************************************************************
  2663.     * Gets and Sets methods.....                                              *
  2664.     **************************************************************************/
  2665.  
  2666.     private function setAspect($value) {
  2667.         $this->aspect = $value;
  2668.         $this->is3D = $this->aspect->getView3D();
  2669.         $this->isOrtho = $this->aspect->getOrthogonal();
  2670.     }
  2671.  
  2672.     /**
  2673.      * Determines the kind of brush used to fill the Canvas draw rectangle
  2674.      * background.<BR>
  2675.      * The Brush.Visible method must be set to true.
  2676.      *
  2677.      * @return ChartBrush 
  2678.      */
  2679.     public function getBrush() {
  2680.         if ($this->brush==null)
  2681.            $this->brush=new ChartBrush(null);
  2682.  
  2683.         return $this->brush;
  2684.     }
  2685.  
  2686.     /**
  2687.      * Determines the kind of brush used to fill the Canvas draw rectangle
  2688.      * background.<BR>
  2689.      * The Brush.Visible method must be set to true.
  2690.      *
  2691.      * @param value ChartBrush
  2692.      */
  2693.     public function setBrush($value) {
  2694.         if ($value!=null)
  2695.           $this->getBrush()->assign($value);
  2696.         else
  2697.           $this->brush=null;
  2698.     }
  2699.  
  2700.     /**
  2701.      * Returns a color from global ColorPalette array variable.
  2702.      *
  2703.      * @param index int
  2704.      * @return Color 
  2705.      */
  2706.     public function getDefaultColor($index) {
  2707.         return $this->colorPalette[$index % sizeof($this->colorPalette)];
  2708.     }
  2709.  
  2710.     /**
  2711.      * Specifies a color from global ColorPalette array variable.
  2712.      *
  2713.      * @param palette Color[]
  2714.      */
  2715.     public function setColorPalette($palette) {
  2716.         $this->colorPalette=$palette;
  2717.         
  2718.         //$colorPalette = Array(); //sizeof($palette.length)];
  2719. /*        for ($t = 0; $t < sizeof($palette); $t++) {
  2720.             $this->colorPalette[$t] = $palette[$t];                        
  2721.         }
  2722.         
  2723.         $this->getChart()->doBaseInvalidate();
  2724.   */    
  2725.         $this->getChart()->doBaseInvalidate();                                             
  2726.     }
  2727.     
  2728.     // Return integer
  2729.     public function getColorPaletteLength() {
  2730.         return sizeof($this->colorPalette);
  2731.     }
  2732.  
  2733.     public function getDirty() {
  2734.         return false;
  2735.     }
  2736.  
  2737.     public function setDirty($value) {}
  2738.  
  2739.     /**
  2740.      * Determines the Font for outputted text when using the Drawing Canvas.
  2741.      *
  2742.      * @return ChartFont 
  2743.      */
  2744.     public function getFont() {
  2745.         return $this->font;
  2746.     }
  2747.  
  2748.     /**
  2749.      * Determines the Font for outputted text when using the Drawing Canvas.
  2750.      *
  2751.      * @param value ChartFont
  2752.      */
  2753.     public function setFont($value) {
  2754.         $this->font->assign($value);
  2755.     }
  2756.  
  2757.     /**
  2758.      * Defines the Height of the Font in pixels.
  2759.      *
  2760.      * @return int 
  2761.      */
  2762.     public function getFontHeight() {
  2763.         return $this->textHeight("W");
  2764.     }
  2765.  
  2766.     public function setGraphics($value) {
  2767.        $this->GraphicsGD=$value;
  2768.     }
  2769.  
  2770.     public function getMetafiling() {
  2771.         return $this->metafiling;
  2772.     }
  2773.  
  2774.     public function setMetafiling($value) {
  2775.         $this->metafiling = $value;
  2776.     }
  2777.  
  2778.     public function getMonochrome() {
  2779.         return $this->monochrome;
  2780.     }
  2781.  
  2782.     /**
  2783.      * Gets / Sets the alignment used when displaying text using TextOut or TextOut3D.
  2784.      * <br>
  2785.      * Default value: Near
  2786.      *
  2787.      * @param value StringAlignment
  2788.      */
  2789.  
  2790.     public function getTextAlign() {
  2791.         return $this->stringFormat->alignment;
  2792.     }
  2793.  
  2794.     public function setTextAlign($value) {
  2795.           if (is_array($value)){
  2796.             $this->stringFormat->alignment=$value;
  2797.           }
  2798.           else {
  2799.            $this->stringFormat->alignment=Array($value);
  2800.           }
  2801.     }
  2802.  
  2803.     /**
  2804.      * Indicates the kind of pen used to draw Canvas lines.
  2805.      *
  2806.      * @return ChartPen 
  2807.      */
  2808.     public function getPen() {
  2809.         return $this->pen;
  2810.     }
  2811.  
  2812.     /**
  2813.      * Determines the kind of pen used to draw Canvas lines.
  2814.      *
  2815.      * @param value ChartPen
  2816.      */
  2817.     public function setPen($value) {
  2818.         if ($value!=null)
  2819.           $this->pen->assign($value);
  2820.     }
  2821.  
  2822.     private function getPenColorStyle() {
  2823.         $penColor = imagecolorallocatealpha($this->img,
  2824.                     $this->pen->getColor()->red,
  2825.                     $this->pen->getColor()->green,
  2826.                     $this->pen->getColor()->blue,
  2827.                     $this->pen->getColor()->alpha);
  2828.                                 
  2829.         switch ($this->pen->getStyle()) {
  2830.             case 1: // DOT
  2831.                 return array($penColor,IMG_COLOR_TRANSPARENT);
  2832.                 break;
  2833.             case 2: // DASH
  2834.                 return array($penColor,$penColor,IMG_COLOR_TRANSPARENT,IMG_COLOR_TRANSPARENT,IMG_COLOR_TRANSPARENT);
  2835.                 break;
  2836.             case 3: // DASHDOT
  2837.                 return array($penColor,$penColor,IMG_COLOR_TRANSPARENT,$penColor);
  2838.                 break;
  2839.             case 4: // DASHDOTDOT
  2840.                 return array($penColor,$penColor,IMG_COLOR_TRANSPARENT,$penColor,IMG_COLOR_TRANSPARENT,$penColor);
  2841.                 break;            
  2842.             default:  // SOLID value 0
  2843.                 return array($penColor);
  2844.                 break;
  2845.         }
  2846.     }
  2847.  
  2848.     /**
  2849.      * Sets the Pixel location (using X,Y,Z) of the centre of rotation for use
  2850.      * with the Aspect Rotation and Elevation properties.<br>
  2851.      *
  2852.      * @return Point3D 
  2853.      */
  2854.     public function getRotationCenter() {
  2855.         return $this->rotationCenter;
  2856.     }
  2857.  
  2858.  
  2859.     /**
  2860.      * Returns the bounding rectangle for a given array of XY points.
  2861.      *
  2862.      * @param num int
  2863.      * @param p Point[]
  2864.      * @return Rectangle 
  2865.      */
  2866.     public function rectFromPolygon($num, $p) {
  2867.         $r = new Rectangle($p[0]->getX(), $p[0]->getY(), 0, 0);
  2868.  
  2869.         for ($t = 1; $t < $num; $t++) {
  2870.             if ($p[$t]->getX() < $r->getX()) {
  2871.                 $r->setX($p[$t]->getX());
  2872.             } else
  2873.             if ($p[$t]->getX() > $r->getRight()) {
  2874.                 $r->setWidth($p[$t]->getX() - $r->getX());
  2875.             }
  2876.  
  2877.             if ($p[$t]->getY() < $r->getY()) {
  2878.                 $r->setY($p[$t]->getY());
  2879.             } else
  2880.             if ($p[$t]->getY() > $r->getBottom()) {
  2881.                 $r->setHeight($p[$t]->getY() - $r->getY());
  2882.             }
  2883.         }
  2884.  
  2885.         $r->width++;
  2886.         $r->height++;
  2887.  
  2888.         return $r;
  2889.     }
  2890.  
  2891.     /**
  2892.      * Obsolete.&nbsp;Please use Rectangle.<!-- -->Contains method.
  2893.      *
  2894.      * @param rect Rectangle
  2895.      * @param x int
  2896.      * @param y int
  2897.      * @return boolean 
  2898.      */
  2899.     static public function pointInRect($rect, $x, $y) {
  2900.         return $rect->contains($x, $y);
  2901.     }
  2902.  
  2903.     /**
  2904.      * Returns true if point P is inside the vert triangle of x0y0, midxY1,
  2905.      * x1y0.
  2906.      *
  2907.      * @param p Point
  2908.      * @param x0 int
  2909.      * @param x1 int
  2910.      * @param y0 int
  2911.      * @param y1 int
  2912.      * @return boolean 
  2913.      */
  2914.     static public function pointInTriangle($p, $x0, $x1, $y0, $y1) {
  2915.         $tmp = Array(new TeePoint($x0, $y0), new TeePoint(($x0 + $x1) / 2, $y1),
  2916.                       new TeePoint($x1, $y0));
  2917.  
  2918.         return $this->pointInPolygon($p, $tmp);
  2919.     }
  2920.  
  2921.     /**
  2922.      * Returns true if point P is inside the horizontal triangle.
  2923.      *
  2924.      * @param p Point
  2925.      * @param y0 int
  2926.      * @param y1 int
  2927.      * @param x0 int
  2928.      * @param x1 int
  2929.      * @return boolean 
  2930.      */
  2931.     static public function pointInHorizTriangle($p, $y0, $y1, $x0, $x1) {
  2932.         $tmp = Array(new TeePoint($x0, $y0), new TeePoint($x1, ($y0 + $y1) / 2),
  2933.                       new TeePoint($x0, $y1));
  2934.         return $this->pointInPolygon($p, $tmp);
  2935.     }
  2936.  
  2937.     /// <summary>
  2938.     /// Returns point "ATo" minus ADist pixels from AFrom point.
  2939.     /// </summary>
  2940.     static public function pointAtDistance($From, $To, $distance)
  2941.     {
  2942.       (int)$px = $To->getX();
  2943.       (int)$py = $To->getY();
  2944.  
  2945.       if ($To->getX() != $From->getX())
  2946.       {
  2947.         $angle = atan2($To->getY() - $From->getY(), $To->getX() - $From->getX());
  2948.         $tmpsin = sin($angle);
  2949.         $tmpcos = cos($angle);
  2950.         $px -= MathUtils::round($distance * $tmpcos);
  2951.         $py -= MathUtils::round($distance * $tmpsin);
  2952.       }
  2953.       else
  2954.       {
  2955.         if ($To->getY() < $From->getY()) $py += $distance;
  2956.         else $py -= $distance;
  2957.       }
  2958.       return new TeePoint($px, $py);
  2959.     }
  2960.  
  2961.     /**
  2962.      * Returns true if point P is inside the ellipse bounded by Left, Top,
  2963.      * Right, Bottom.
  2964.      *
  2965.      * @param p Point
  2966.      * @param left int
  2967.      * @param top int
  2968.      * @param right int
  2969.      * @param bottom int
  2970.      * @return boolean 
  2971.      */
  2972.     static public function _pointInEllipse($p, $left, $top, $right, $bottom) {
  2973.         return $this->pointInEllipse($p, Rectangle::fromLTRB($left, $top, $right, $bottom));
  2974.     }
  2975.  
  2976.     /**
  2977.      * Returns true if point P is inside the ellipse bounded by Rect.
  2978.      *
  2979.      * @param p Point
  2980.      * @param rect Rectangle
  2981.      * @return boolean 
  2982.      */
  2983.     static public function pointInEllipse($p, $rect) {
  2984.         $tmp = $rect->center();
  2985.         $tmpWidth = (int) sqr($tmp->getX() - $rect->getX());
  2986.         $tmpHeight = (int) sqr($tmp->getY() - $rect->getY());
  2987.  
  2988.         return ($tmpWidth != 0) && ($tmpHeight != 0) &&
  2989.                 ((sqr($p->getX() - $tmp->getX()) / $tmpWidth) +
  2990.                  (sqr($p->getY() - $tmp->getY()) / $tmpHeight) <= 1
  2991.                 );
  2992.     }
  2993.  
  2994.     /**
  2995.      * Returns true if point P is inside Poly polygon.
  2996.      *
  2997.      * @param p Point
  2998.      * @param poly Point[]
  2999.      * @return boolean 
  3000.      */
  3001.     static public function pointInPolygon($p, $poly) {
  3002.         $result = false;
  3003.         (int)$j = sizeof($poly) - 1;
  3004.         (int)$tmp = $j;
  3005.  
  3006.         for ($i = 0; $i <= $tmp; $i++) {
  3007.             if ((((($poly[$i]->getY() <= $p->getY()) && ($p->getY() < $poly[$j]->getY())) ||
  3008.                   (($poly[$j]->getY() <= $p->getY()) && ($p->getY() < $poly[$i]->getY()))) &&
  3009.                  ($p->getX() < ($poly[$j]->getX() - $poly[$i]->getX()) * ($p->getY() - $poly[$i]->getY())
  3010.                   / ($poly[$j]->getY() - $poly[$i]->getY()) + $poly[$i]->getX()))) {
  3011.                 $result = !$result;
  3012.             }
  3013.             $j = $i;
  3014.         }
  3015.  
  3016.         return $result;
  3017.     }
  3018.  
  3019.     // Returns boolean
  3020.     protected function getIZoomfactor() {
  3021.         return $this->iZoomFactor;
  3022.     }
  3023.  
  3024.     protected function setIZoomfactor($value) {
  3025.         $this->iZoomFactor = $value;
  3026.     }
  3027.  
  3028.     /**
  3029.      * The X coordinate of the pixel location of the center of the 3D
  3030.      * Canvas.<br>
  3031.      * The origin of the pixel coordinate system is in the top left corner of
  3032.      * the parent window.
  3033.      *
  3034.      * @return int 
  3035.      */
  3036.     public function getXCenter() {
  3037.         return $this->xCenter;
  3038.     }
  3039.  
  3040.     /**
  3041.      * Specifies the X coordinate of the pixel location of the center of the 3D
  3042.      * Canvas.<br>
  3043.      * The origin of the pixel coordinate system is in the top left corner of
  3044.      * the parent window.
  3045.      *
  3046.      * @param value int
  3047.      */
  3048.     public function setXCenter($value) {
  3049.         $this->xCenter = $value;
  3050.     }
  3051.  
  3052.     /**
  3053.      * The Y coordinate of the pixel location of the center of the 3D
  3054.      * Canvas.<br>
  3055.      * The origin of the pixel coordinate system is in the top left corner of
  3056.      * the parent window.
  3057.      *
  3058.      * @return int 
  3059.      */
  3060.     public function getYCenter() {
  3061.         return $this->yCenter;
  3062.     }
  3063.  
  3064.     /**
  3065.      * Specifies the Y coordinate of the pixel location of the center of the 3D
  3066.      * Canvas.<br>
  3067.      * The origin of the pixel coordinate system is in the top left corner of
  3068.      * the parent window.
  3069.      *
  3070.      * @param value int
  3071.      */
  3072.     public function setYCenter($value) {
  3073.         $this->yCenter = $value;
  3074.     }
  3075.  
  3076.     /**
  3077.      * Returns a valid Windows Brush Style from anpalette of many possible
  3078.      * Brush styles.
  3079.      *
  3080.      * @param index int
  3081.      * @return HatchStyle 
  3082.      */
  3083.     static public function getDefaultPattern($index) {
  3084.         $patternPalette = Array (
  3085.                                       HatchStyle::$HORIZONTAL,
  3086.                                       HatchStyle::$VERTICAL,
  3087.                                       HatchStyle::$FORWARDDIAGONAL,
  3088.                                       HatchStyle::$BACKWARDDIAGONAL,
  3089.                                       HatchStyle::$CROSS,
  3090.                                       HatchStyle::$DIAGONALCROSS,
  3091.                                       HatchStyle::$DIAGONALBRICK,
  3092.                                       HatchStyle::$DIVOT,
  3093.                                       HatchStyle::$LARGECONFETTI,
  3094.                                       HatchStyle::$OUTLINEDDIAMOND,
  3095.                                       HatchStyle::$PLAID,
  3096.                                       HatchStyle::$SHINGLE,
  3097.                                       HatchStyle::$SOLIDDIAMOND,
  3098.                                       HatchStyle::$SPHERE,
  3099.                                       HatchStyle::$TRELLIS,
  3100.                                       HatchStyle::$WAVE,
  3101.                                       HatchStyle::$WEAVE,
  3102.                                       HatchStyle::$ZIGZAG
  3103.         );
  3104.         return $patternPalette[$index % sizeof($patternPalette)];
  3105.     }
  3106.  
  3107.  
  3108.     /**
  3109.      * The anti-alias mode for the Graphics Pen when Custom drawing.<br>
  3110.      * For example: <br>
  3111.      *             AntiAlias - Specifies antialiased rendering.<br>
  3112.      *             Default - Specifies the default mode.<br>
  3113.      *             HighQuality - Specifies high quality, low speed rendering.
  3114.      * <br>
  3115.      *             HighSpeed - Specifies high speed, low quality rendering.<br>
  3116.      *             Invalid - Specifies an invalid mode.  <br>
  3117.      *
  3118.      * @return boolean 
  3119.      */
  3120.     public function getSmoothingMode() {
  3121.         return $this->smoothingMode;
  3122.     }
  3123.  
  3124.     /**
  3125.      * Sets the anti-alias mode for the Graphics Pen when Custom drawing.<br>
  3126.      * For example: <br>
  3127.      *             AntiAlias - Specifies antialiased rendering.<br>
  3128.      *             Default - Specifies the default mode.<br>
  3129.      *             HighQuality - Specifies high quality, low speed rendering.
  3130.      * <br>
  3131.      *             HighSpeed - Specifies high speed, low quality rendering.<br>
  3132.      *             Invalid - Specifies an invalid mode.  <br>
  3133.      *
  3134.  
  3135.      * @param value boolean
  3136.      */
  3137.     public function setSmoothingMode($value) {
  3138.         $this->smoothingMode = $this->setBooleanProperty($this->smoothingMode, $value);
  3139.     }
  3140.  
  3141.     static private function internalGetSupports3DText() {
  3142.         return false;
  3143.     }
  3144.  
  3145.     /**
  3146.      * Returns if Canvas supports 3D Text or not.
  3147.      *
  3148.      * @return boolean 
  3149.      */
  3150.     public function getSupports3DText() {
  3151.         return self::internalGetSupports3DText();
  3152.     }
  3153.  
  3154.     /**
  3155.      * Returns if Canvas can do rotation and elevation of more than 90 degree.
  3156.      *
  3157.      * @return boolean 
  3158.      */
  3159.     public function getSupportsFullRotation() {
  3160.         return false;
  3161.     }
  3162.  
  3163.     // Returns TeePoint
  3164.     static public function rectCenter($r) {
  3165.         return new TeePoint(
  3166.                 ($r->getX() + $r->getRight()) / 2,
  3167.                 ($r->y + $r->getBottom()) / 2
  3168.                 );
  3169.     }
  3170.  
  3171.     // returns PointDouble
  3172.     public function pointFromCircle($rectBounds, $degrees,
  3173.                                        $zPos, $clockWise=false)
  3174.     {
  3175.       $centrePoint = $this->rectCenter($rectBounds);
  3176.  
  3177.       $radians = (M_PI * $degrees) / 180.0;
  3178.       $radiusH = $rectBounds->getWidth() / 2.0;
  3179.       $radiusV = $rectBounds->getHeight() / 2.0;
  3180.  
  3181.       $tmpX = $centrePoint->getX() + $radiusH * cos($radians);
  3182.       $tmpY = 0;
  3183.       if ($clockWise)
  3184.       {
  3185.         $tmpY = $centrePoint->getY() + $radiusV * sin($radians);
  3186.       }
  3187.       else
  3188.       {
  3189.         $tmpY = $centrePoint->getY() - $radiusV * sin($radians);
  3190.       }
  3191.  
  3192.       if ($zPos > 0)
  3193.       {
  3194.         $tmpPoint = $this->calc3DPos($tmpX,$tmpY,$zPos);
  3195.       }
  3196.       else
  3197.       {
  3198.         $tmpPoint = new PointDouble($tmpX, $tmpY);
  3199.       }
  3200.  
  3201.       return $tmpPoint;
  3202.     }
  3203.  
  3204.     public function getImageInterlace()
  3205.     {
  3206.         return $this->imageinterlace;
  3207.     }
  3208.  
  3209.     public function setImageInterlace($vlaue)
  3210.     {
  3211.         $this->imageinterlace=$value;
  3212.     }
  3213.  
  3214.     public function getImageReflection()
  3215.     {
  3216.         return $this->imageReflection;
  3217.     }
  3218.  
  3219.     public function setImageReflection($value)
  3220.     {
  3221.         $this->imageReflection=$value;
  3222.     }
  3223.  
  3224.     /**
  3225.      * Converts the Color parameter to a darker color.<br>
  3226.      * The HowMuch parameter indicates the quantity of dark increment.
  3227.      * It is used by Bar Series and Pie Series to calculate the right color to
  3228.      * draw Bar sides and Pie 3D zones.
  3229.      *
  3230.      * @param c Color
  3231.      * @param howMuch int
  3232.      * @return Color 
  3233.      */
  3234.     static public function applyDark($c, $howMuch) {
  3235.         return $c->applyDark($howMuch);
  3236.     }
  3237.  
  3238.     public static function doReflection($im) {
  3239.  
  3240.         $rH = 50; // Reflection height
  3241.         $tr = 30; // Starting transparency
  3242.         $div = 1; // Size of the divider line
  3243.  
  3244.         $w=imagesx($im);
  3245.         $h=imagesy($im);
  3246.  
  3247.         $imgFinal = $im;
  3248.  
  3249.         $li = imagecreatetruecolor($w, 1);
  3250.         $bgc = imagecolorallocate($li, 255, 255, 255); // Background color
  3251.         imagefilledrectangle($li, 0, 0, $w, 1, $bgc);
  3252.         $bg = imagecreatetruecolor($w, $rH);
  3253.         $wh = imagecolorallocate($im,255,255,255);
  3254.  
  3255.         $im = imagerotate($im, -180, $wh);
  3256.         imagecopyresampled($bg, $im, 0, 0, 0, 0, $w, $h, $w, $h);
  3257.         $im = $bg;
  3258.         $bg = imagecreatetruecolor($w, $rH);
  3259.  
  3260.         for ($x = 0; $x < $w; $x++) {
  3261.           imagecopy($bg, $im, $x, 0, $w-$x, 0, 1, $rH);
  3262.         }
  3263.  
  3264.         $im = $bg;
  3265.         $in = 100/$rH;
  3266.  
  3267.         for($i=0; $i<=$rH; $i++){
  3268.           if($tr>100) $tr = 100;
  3269.             imagecopymerge($im, $li, 0, $i, 0, 0, $w, 1, $tr);
  3270.           $tr+=$in;
  3271.         }
  3272.  
  3273.         imagecopymerge($im, $li, 0, 0, 0, 0, $w, $div, 100); // Divider
  3274.  
  3275.         return $im;
  3276.         imagedestroy($li);
  3277.     }
  3278.  
  3279.  
  3280.     /**
  3281.      * Returns the height, in pixels, of the Chart Panel.<br>
  3282.      * It should be used when using Canvas methods to draw relative to the
  3283.      * Panel height. <br>
  3284.      * <b>Note:</B> You should <b>NOT</b> use TChart.Height.
  3285.  
  3286.      *
  3287.      * @return int 
  3288.      */
  3289.     static public function getScreenHeight() {
  3290.         return 1050;  // TODO GET SCREEN WIDTH AND HEIGHT
  3291.     }
  3292.  
  3293.     /**
  3294.      * Returns the width, in pixels, of the Chart Panel.
  3295.      *
  3296.      * @return int 
  3297.      */
  3298.     static public function getScreenWidth() {
  3299.         return 1680;  // TODO GET SCREEN WIDTH AND HEIGHT
  3300.     }
  3301.  
  3302. }
  3303.  
  3304.  
  3305.  /*****************************************************************************
  3306.  *   Class Pie 3D.........
  3307.  *****************************************************************************/
  3308.  
  3309.  final class Pie3D {
  3310.  
  3311.         // Private properties
  3312.         private $g;
  3313.         private $dark;
  3314.         private $tmpXRadius, $tmpYRadius;
  3315.         private $donut;
  3316.         private $center;
  3317.         private $z0Rect;       // Rect
  3318.         private $z1Rect;       // Rect
  3319.         private $z0DonutRect;  // Rect
  3320.         private $z1DonutRect;  // Rect
  3321.         private $z0BevelRect;  // Rect
  3322.         private $z1BevelRect;  // Rect
  3323.         private $zPos;
  3324.         private $iStartAngle;
  3325.         private $iEndAngle;
  3326.         private $sweepAngle;
  3327.         private $isDonut;
  3328.         private $drawEntirePie;
  3329.         private $iDrawSides;
  3330.         private $hasBevel;
  3331.         private $middle0;   // PointDouble
  3332.         private $middle1;   // PointDouble
  3333.         private $start0;    // PointDouble
  3334.         private $end0;      // PointDouble
  3335.         private $start1;    // PointDouble
  3336.         private $end1;      // PointDouble
  3337.         private $startD0;   // PointDouble
  3338.         private $endD0;     // PointDouble
  3339.         private $startD1;   // PointDouble
  3340.         private $endD1;     // PointDouble
  3341.         private $startB0;   // PointDouble
  3342.         private $endB0;     // PointDouble
  3343.         private $startB1;   // PointDouble
  3344.         private $endB1;     // PointDouble
  3345.         private $ilist;     // PointDouble[0];
  3346.         private $gradientBrush;
  3347.  
  3348.         // Public properties
  3349.         public $MAXPIESTEPS = 32;
  3350.         public $points;
  3351.         public $points3D2;
  3352.         public $points3D;
  3353.         public $start3D, $end3D, $circleSteps;
  3354.         public $oldColor;
  3355.  
  3356.  
  3357.         public function Pie3D($graphics) {
  3358.  
  3359.             $this->points = Array(); 
  3360.             $this->points3D2 = Array(); 
  3361.             $this->points3D = Array(); 
  3362.             $this->center = new TeePoint();
  3363.  
  3364.             $this->g = $graphics;
  3365.  
  3366.             $this->ilist= Array();           
  3367.         }
  3368.  
  3369.         public function draw3DPie() {
  3370.  
  3371.             if ($this->dark) {
  3372.                 $this->g->internalApplyDark($this->oldColor, 32);
  3373.             }
  3374.  
  3375.             if (($this->start3D == 1) && ($this->end3D == $this->circleSteps)) {
  3376.                 for ( $t = 1; $t <= $this->circleSteps; $t++) {
  3377.                     $this->points3D[$t - 1] = $this->points[$t];
  3378.                 }
  3379.                 $tt = $this->circleSteps;
  3380.             } else {
  3381.                 $tt = 0;
  3382.                 for ( $t = $this->start3D; $t <= $this->end3D; $t++) {
  3383.                     $this->points3D[$tt] = $this->points[$t];
  3384.                     $this->points3D[$this->end3D - $this->start3D + 1 +
  3385.                             $tt] = $this->points3D[2 * $this->circleSteps - $this->end3D + $tt];
  3386.                     $tt++;
  3387.                 }
  3388.             }
  3389.  
  3390.             $c1 = imagecolorallocate($this->g->img, $this->g->getBrush()->getColor()->red,
  3391.               $this->g->getBrush()->getColor()->green,
  3392.               $this->g->getBrush()->getColor()->blue);
  3393.  
  3394.             $p1 = imagecolorallocate($this->g->img, $this->g->getPen()->getColor()->red,
  3395.               $this->g->getPen()->getColor()->green,
  3396.               $this->g->getPen()->getColor()->blue);
  3397.  
  3398.             $tmpArray = Array();
  3399.             $tmpArray=$this->g->sliceArray($this->points3D, 2 * $tt);
  3400.  
  3401.             $tmpArray2= Array();
  3402.  
  3403.             for ($tt=0;$tt < count($tmpArray); $tt++) {
  3404.                $tmpTeePoint = $tmpArray[$tt];
  3405.                  $tmpX=$tmpTeePoint->getX();
  3406.                  $tmpY=$tmpTeePoint->getY();
  3407.                  $tmpArray2[]=$tmpX;
  3408.                  $tmpArray2[]=$tmpY;
  3409.             }
  3410.  
  3411.             if (count($tmpArray2) >= 3) {
  3412.                 imageantialias($this->g->img,true);
  3413.                 imagefilledpolygon($this->g->img, $tmpArray2, count($tmpArray2)/2, $c1);
  3414.                 imagepolygon($this->g->img, $tmpArray2, count($tmpArray2)/2, $p1);
  3415.                 imageantialias($this->g->img,false);
  3416.             }
  3417.         }
  3418.  
  3419.         private function calcCenter($angle, $z) {
  3420.             if ($this->donut > 0) {
  3421.                  $tmpSin = sin($angle);
  3422.                  $tmpCos = cos($angle);
  3423.                  $tmpX = $this->center->x + MathUtils::round($this->tmpXRadius * $tmpCos);
  3424.                  $tmpY = $this->center->y - MathUtils::round($this->tmpYRadius * $tmpSin);
  3425.                 return $this->g->calc3DPos($tmpX, $tmpY, $z);
  3426.             } else {
  3427.                 return $this->g->calc3DPos($this->center->getX(), $this->center->getY(), $z);
  3428.             }
  3429.         }
  3430.  
  3431.         private function finishSide($angle, $z) {
  3432.             $this->g->iPoints[3] = $this->calcCenter($angle, $z);
  3433.             if ($this->dark) {
  3434.                 $this->g->internalApplyDark($this->oldColor, 32);
  3435.             }
  3436.             $this->g->polygonFour();
  3437.         }
  3438.  
  3439.         private function redimArray($count, $index, $points)
  3440.         {
  3441.           $tmpArr = Array();
  3442.           $loc = 0;
  3443.           for ($i=$index;$i<(sizeof($points)+$index);$i++)
  3444.           {
  3445.              $tmpArr[$i] = $points[$loc];
  3446.              $loc++;
  3447.           }
  3448.  
  3449.           return $tmpArr;
  3450.         }
  3451.  
  3452.         private function addToList($point)
  3453.         {
  3454. //          /*PointDouble[]*/ $tmpList=$this->redimArray(sizeof($this->ilist)+1,0,$this->ilist);
  3455.           //$tmpList[sizeof($tmpList)-1]=$point;
  3456.           //$this->ilist = $tmpList;
  3457.           $this->ilist[sizeof($this->ilist)] = $point;
  3458.         }
  3459.  
  3460.         // Returns PointDouble
  3461.         public function pointD($rect, $angle, $z)
  3462.         {
  3463.           return $this->g->pointFromCircle($rect, $angle, $z);  
  3464.         }
  3465.  
  3466.         public function pie($xCenter, $yCenter,
  3467.           $xRadius, $yRadius, $z0, $z1, $startAngle,
  3468.           $endAngle, $darkSides, $drawSides, $donutPercent=0,
  3469.           $bevelPercent=0, $edgeStyle=0, $last=false /*, Shadow shadow*/)
  3470.         {
  3471.           $tmpP = new TeePoint();
  3472.  
  3473.           $this->isDonut = false;
  3474.           $this->hasBevel = false;
  3475.  
  3476.           $tmpP->setX($xCenter);
  3477.           $tmpP->setY($yCenter);
  3478.  
  3479.           $left0 = $tmpP->getX() - $xRadius;
  3480.           $right0 = $tmpP->getX() + $xRadius;
  3481.           $top0 = $tmpP->getY() - $yRadius;
  3482.           $bottom0 = $tmpP->getY() + $yRadius;
  3483.  
  3484.           $this->zPos = $z1 - $z0;
  3485.  
  3486.           $this->z0Rect = Rectangle::fromLTRB($left0, $top0, $right0, $bottom0);
  3487.           $this->z1Rect = Rectangle::fromLTRB($this->z0Rect->getLeft(), $this->z0Rect->getTop()+$this->zPos,
  3488.                                       $this->z0Rect->getRight(), $this->z0Rect->getBottom()+$this->zPos);
  3489.  
  3490.           $this->iDrawSides = $drawSides;
  3491.  
  3492.           $this->iStartAngle = (int)MathUtils::round(($startAngle * 180.0) / M_PI );
  3493.           $this->iEndAngle = (int)MathUtils::round(($endAngle * 180.0) /  M_PI );
  3494.  
  3495.           if ($this->iEndAngle < $this->iStartAngle)
  3496.           {
  3497.             $this->iEndAngle += 360;
  3498.           }
  3499.           if ($this->g->getBrush()->getSolid())
  3500.             $this->oldColor = $this->g->getBrush()->getColor();
  3501.           else
  3502.             $this->oldColor = $this->g->getBackColor();
  3503.  
  3504.           $shadowColor = Color::fromArgb(0, 0, 0, 0); //Utils::getEmptyColor();
  3505.  
  3506.           /*
  3507.           if (shadow!=null && shadow.Visible)
  3508.           {
  3509.             shadowColor = shadow.Brush.Color;
  3510.           }
  3511.            */
  3512.  
  3513.           $this->drawEntirePie = $this->g->getBrush()->getTransparency() > 0 && $this->g->getChart()->getAspect()->getView3D();
  3514.  
  3515.           if ($donutPercent > 0)
  3516.           {
  3517.             $tmpXRadius = $donutPercent * $xRadius * 0.01;
  3518.             $tmpYRadius = $donutPercent * $yRadius * 0.01;
  3519.  
  3520.             $left0 = (int)MathUtils::round($tmpP->getX() - $tmpXRadius);
  3521.             $right0 = (int)MathUtils::round($tmpP->getX() + $tmpXRadius);
  3522.             $top0 = (int)MathUtils::round($tmpP->getY() - $tmpYRadius);
  3523.             $bottom0 = (int)MathUtils::round($tmpP->getY() + $tmpYRadius);
  3524.  
  3525.             $this->z0DonutRect = Rectangle::fromLTRB($left0, $top0, $right0, $bottom0);
  3526.             $this->z1DonutRect = Rectangle::fromLTRB($this->z0DonutRect->getLeft(), $this->z0DonutRect->getTop()+$this->zPos,
  3527.                                              $this->z0DonutRect->getRight(), $this->z0DonutRect->getBottom()+$this->zPos);
  3528.  
  3529.             $this->startD0 = $this->pointD($this->z0DonutRect, $this->iStartAngle, $this->zPos);
  3530.             $this->endD0 = $this->pointD($this->z0DonutRect, $this->iEndAngle, $this->zPos);
  3531.  
  3532.             $this->startD1 = $this->pointD($this->z1DonutRect, $this->iStartAngle, $this->zPos);
  3533.             $this->endD1 = $this->pointD($this->z1DonutRect, $this->iEndAngle, $this->zPos);
  3534.  
  3535.             $this->isDonut = true;
  3536.           }
  3537.  
  3538.           if ($bevelPercent > 0)
  3539.           {
  3540.             $bevelAmount = $bevelPercent * $this->zPos * 0.01;
  3541.  
  3542.             $left0 = (int)MathUtils::round($tmpP->getX() - ($xRadius - $bevelAmount));
  3543.             $right0 = (int)MathUtils::round($tmpP->getX() + ($xRadius - $bevelAmount));
  3544.             $top0 = (int)MathUtils::round($tmpP->getY() - ($yRadius - $bevelAmount));
  3545.             $bottom0 = (int)MathUtils::round($tmpP->getY() + ($yRadius - $bevelAmount));
  3546.  
  3547.             $this->z0BevelRect = Rectangle::fromLTRB($left0, $top0, $right0, $bottom0);
  3548.             $this->z1BevelRect = Rectangle::fromLTRB($this->z0Rect->getLeft(),
  3549.                                              $this->z0Rect->getTop()+(int)MathUtils::round($bevelAmount),
  3550.                                              $this->z0Rect->getRight(),
  3551.                                              $this->z0Rect->getBottom()+(int)MathUtils::round($bevelAmount));
  3552.             //z1BevelRect.Offset(0.0, bevelAmount);
  3553.  
  3554.             $this->startB0 = $this->pointD($this->z0BevelRect, $this->iStartAngle, $this->zPos);
  3555.             $this->endB0 = $this->pointD($this->z0BevelRect, $this->iEndAngle, $this->zPos);
  3556.  
  3557.             $this->startB1 = $this->pointD($this->z1BevelRect, $this->iStartAngle, $this->zPos);
  3558.             $this->endB1 = $this->pointD($this->z1BevelRect, $this->iEndAngle, $this->zPos);
  3559.  
  3560.             $this->hasBevel = true;
  3561.           }
  3562.  
  3563.           $this->middle0 = $this->g->calc3DPosDouble($tmpP->getX(), $tmpP->getY(), $this->zPos, true);
  3564.           $this->middle1 = $this->g->calc3DPosDouble($tmpP->getX(), $tmpP->getY() + $this->zPos, $this->zPos, true);
  3565.  
  3566.           $this->start0 = $this->pointD($this->z0Rect, $this->iStartAngle, $this->zPos);
  3567.           $this->end0 = $this->pointD($this->z0Rect, $this->iEndAngle, $this->zPos);
  3568.  
  3569.           $this->start1 = $this->pointD($this->z1Rect, $this->iStartAngle, $this->zPos);
  3570.           $this->end1 = $this->pointD($this->z1Rect, $this->iEndAngle, $this->zPos);
  3571.  
  3572.           $this->sweepAngle = $this->iEndAngle - $this->iStartAngle;
  3573.  
  3574.           $this->drawBottom($this->iStartAngle, $this->iEndAngle);
  3575.  
  3576.           $invisiblePen = !$this->g->getPen()->getVisible(); //g.getPen().getColor() == oldColor;
  3577.  
  3578.           if ($darkSides)
  3579.           {
  3580.               $this->g->internalApplyDark($this->oldColor, 32);
  3581.               $c = $this->oldColor;
  3582.               if ($invisiblePen)
  3583.                   $c = GraphicsGD::applyDark($c, 32);
  3584.               else
  3585.                   $c = GraphicsGD::applyDark($c, 64);
  3586.               $this->g->getPen()->setColor($c);
  3587.           }
  3588.  
  3589.           $this->drawSides($this->iStartAngle, $this->iEndAngle);
  3590.           if ($darkSides)
  3591.           {
  3592.               if ($this->g->getBrush()->getSolid())
  3593.                   $this->g->getBrush()->setColor($this->oldColor);
  3594.               else
  3595.                   $this->g->setBackColor($this->oldColor);
  3596.               if ($invisiblePen)
  3597.               {
  3598.                   $this->g->getPen()->setColor($this->oldColor);
  3599.               }
  3600.           }
  3601.           $this->drawTop($this->iStartAngle, $this->iEndAngle);
  3602.  
  3603.           $this->drawLighting($edgeStyle,$last);
  3604.         }
  3605.  
  3606.         private function drawSides($startAng, $endAng)
  3607.         {
  3608.           $this->ilist=Array();
  3609.  
  3610.           if ($this->end0->getX() > $this->middle0->getX())
  3611.           {
  3612.             if ($this->start0->getX() < $this->middle0->getX())
  3613.             {
  3614.               $this->drawBack($startAng, $endAng);
  3615.               $this->drawRight();
  3616.               $this->drawLeft();
  3617.               $this->drawFront($startAng, $endAng);
  3618.             }
  3619.             else
  3620.             {
  3621.               if ($this->sweepAngle > 180)
  3622.               {
  3623.                 $this->drawBack($startAng, $endAng);
  3624.                 $this->drawRight();
  3625.                 $this->drawLeft();
  3626.                 $this->drawFront($startAng, $endAng);
  3627.               }
  3628.               else
  3629.               {
  3630.                 $this->drawLeft();
  3631.                 $this->drawBack($startAng, $endAng);
  3632.                 $this->drawFront($startAng, $endAng);
  3633.                 $this->drawRight();
  3634.               }
  3635.             }
  3636.           }
  3637.           else
  3638.           {
  3639.             if ($this->start0->getX() < $this->middle0->getX())
  3640.             {
  3641.               if ($this->sweepAngle > 180)
  3642.               {
  3643.                 $this->drawBack($startAng, $endAng);
  3644.                 $this->drawLeft();
  3645.                 $this->drawRight();
  3646.                 $this->drawFront($startAng, $endAng);
  3647.               }
  3648.               else
  3649.               {
  3650.                 $this->drawRight();
  3651.                 $this->drawBack($startAng, $endAng);
  3652.                 $this->drawFront($startAng, $endAng);
  3653.                 $this->drawLeft();
  3654.               }
  3655.             }
  3656.             else
  3657.             {
  3658.               if ($this->sweepAngle > 180)
  3659.               {
  3660.                 $this->drawBack($startAng, $endAng);
  3661.                 $this->drawLeft();
  3662.                 $this->drawFront($startAng, $endAng);
  3663.                 $this->drawRight();
  3664.               }
  3665.               else
  3666.               {
  3667.                 $this->drawBack($startAng, $endAng);
  3668.                 $this->drawFront($startAng, $endAng);
  3669.                 $this->drawRight();
  3670.                 $this->drawLeft();
  3671.               }
  3672.             }
  3673.           }
  3674.         }
  3675.  
  3676.         private function drawBack($startAng, $endAng)
  3677.         {
  3678.           $doDrawBack = $this->isDonut;
  3679.  
  3680.           $this->ilist= Array();
  3681.           //$this->ilist[0]=new PointDouble();
  3682.  
  3683.           if (!$this->drawEntirePie && $doDrawBack &&
  3684.                  $this->start0->getY() > $this->middle0->getY() &&
  3685.                  $this->end0->getY() > $this->middle0->getY() &&
  3686.                  $this->sweepAngle < 180)
  3687.           {
  3688.             $doDrawBack = false;
  3689.           }
  3690.  
  3691.           if ($doDrawBack)
  3692.           {
  3693.             for ($i = $startAng; $i <= $endAng; $i=$i + 0.25)
  3694.             {
  3695.               $this->addToList($this->pointD($this->z0DonutRect, $i, $this->zPos));
  3696.             }
  3697.  
  3698.             for ($i = $endAng; $i >= $startAng; $i=$i - 0.25)
  3699.             {
  3700.               $this->addToList($this->pointD($this->z1DonutRect, $i, $this->zPos));
  3701.             }
  3702.  
  3703.             $this->drawPoints();
  3704.           }
  3705.         }
  3706.  
  3707.         private function drawFront($startAng, $endAng)
  3708.         {
  3709.           $doDrawFront = true;
  3710.  
  3711.           if ((!$this->drawEntirePie &&
  3712.                 $this->start0->getY() < $this->middle0->getY() &&
  3713.                 $this->end0->getY() < $this->middle0->getY()
  3714.                 && $this->sweepAngle < 180))
  3715.           {
  3716.             $doDrawFront = false;
  3717.             $this->drawBevel($startAng, $endAng);
  3718.           }
  3719.  
  3720.           if ($doDrawFront)
  3721.           {
  3722.             $this->ilist=Array();
  3723.             //$this->ilist[0]=new PointDouble();
  3724.  
  3725.             $tmpEndAng = $endAng;
  3726.             $tmpStartAng = $startAng;
  3727.  
  3728.             while ($tmpEndAng > 360)
  3729.               $tmpEndAng -= 360;
  3730.  
  3731.             while ($tmpEndAng < -360)
  3732.               $tmpEndAng += 360;
  3733.  
  3734.             while ($tmpStartAng > 360)
  3735.               $tmpStartAng -= 360;
  3736.  
  3737.             while ($tmpStartAng < -360)
  3738.               $tmpStartAng += 360;
  3739.  
  3740.             if ($tmpEndAng < 0) {
  3741.               $tmpEndAng = 360 + $tmpEndAng;
  3742.             }
  3743.  
  3744.             if ($tmpStartAng < 0) {
  3745.               $tmpStartAng = 360 + $tmpStartAng;
  3746.             }
  3747.  
  3748.             if ($this->start0->getY() > $this->middle0->getY() &&
  3749.                     $this->end0->getY() < $this->middle0->getY())            //right
  3750.             {
  3751.               if ($this->drawEntirePie)
  3752.               {
  3753.                 if ($this->hasBevel) {
  3754.                   for ($i = 0; $i <= $tmpEndAng; $i=$i + 0.25) {
  3755.                     $this->addToList($this->pointD($this->z1BevelRect, $i, $this->zPos));
  3756.                   }
  3757.                 }
  3758.                 else {
  3759.                   for ($i = 0; $i <= $tmpEndAng; $i=$i + 0.25) {
  3760.                     $this->addToList($this->pointD($this->z0Rect, $i, $this->zPos));
  3761.                   }
  3762.                 }
  3763.  
  3764.                 for ($i = $tmpEndAng; $i >= 0; $i=$i - 0.25) {
  3765.                   $this->addToList($this->pointD($this->z1Rect, $i, $this->zPos));
  3766.                 }
  3767.  
  3768.                 $this->drawPoints();
  3769.               }
  3770.  
  3771.               if ($tmpStartAng > 0) {
  3772.                 for ($i = 360; $i >= $tmpStartAng; $i=$i - 0.25) {
  3773.                   $this->addToList($this->pointD($this->z1Rect, $i, $this->zPos));
  3774.                 }
  3775.  
  3776.                 if ($this->hasBevel) {
  3777.                   for ($i = $tmpStartAng; $i <= 360; $i=$i + 0.25) {
  3778.                     $this->addToList($this->pointD($this->z1BevelRect, $i, $this->zPos));
  3779.                   }
  3780.                 }
  3781.                 else {
  3782.                   for ($i = $tmpStartAng; $i <= 360; $i=$i + 0.25) {
  3783.                     $this->addToList($this->pointD($this->z0Rect, $i, $this->zPos));
  3784.                   }
  3785.                 }
  3786.  
  3787.                 $this->drawPoints();
  3788.               }
  3789.               $this->drawBevel($tmpStartAng, $tmpEndAng);
  3790.             }
  3791.             else if ($this->start0->getY() < $this->middle0->getY() && $this->end0->getY() > $this->middle0->getY())        //left
  3792.             {
  3793.               if ($this->drawEntirePie) {
  3794.                 if ($this->hasBevel) {
  3795.                   for ($i = 180; $i >= $tmpStartAng; $i=$i - 0.25) {
  3796.                     $this->addToList($this->pointD($this->z1BevelRect, $i, $this->zPos));
  3797.                   }
  3798.                 }
  3799.                 else {
  3800.                   for ($i = 180; $i >= $tmpStartAng; $i=$i - 0.25) {
  3801.                     $this->addToList($this->pointD($this->z0Rect, $i, $this->zPos));
  3802.                   }
  3803.                 }
  3804.  
  3805.                 for ($i = $tmpStartAng; $i <= 180; $i=$i + 0.25) {
  3806.                   $this->addToList($this->pointD($this->z1Rect, $i, $this->zPos));
  3807.                 }
  3808.                 $this->drawPoints();
  3809.               }
  3810.  
  3811.               for ($i = 180; $i <= $tmpEndAng; $i=$i + 0.25) {
  3812.                 $this->addToList($this->pointD($this->z1Rect, $i, $this->zPos));
  3813.               }
  3814.  
  3815.               if ($this->hasBevel) {
  3816.                 for ($i = $tmpEndAng; $i >= 180; $i=$i - 0.25) {
  3817.                   $this->addToList($this->pointD($this->z1BevelRect, $i, $this->zPos));
  3818.                 }
  3819.               }
  3820.               else {
  3821.                 for ($i = $tmpEndAng; $i >= 180; $i=$i - 0.25) {
  3822.                   $this->addToList($this->pointD($this->z0Rect, $i, $this->zPos));
  3823.                 }
  3824.               }
  3825.  
  3826.               $this->drawPoints();
  3827.               $this->drawBevel($tmpStartAng, $tmpEndAng);
  3828.             }
  3829.             else if ($this->start0->getY() >= $this->middle0->getY() &&
  3830.                   $this->end0->getY() > $this->middle0->getY() &&
  3831.                   $this->sweepAngle > 180)        //front
  3832.             {
  3833.  
  3834.               if ($this->hasBevel) {
  3835.                 for ($i = 180; $i >= 0; $i=$i - 0.25) {
  3836.                   $this->addToList($this->pointD($this->z1BevelRect, $i, $this->zPos));
  3837.                 }
  3838.               }
  3839.               else {
  3840.                 for ($i = 180; $i >= 0; $i=$i - 0.25) {
  3841.                   $this->addToList($this->pointD($this->z0Rect, $i, $this->zPos));
  3842.                 }
  3843.               }
  3844.  
  3845.               for ($i = 0; $i <= 180; $i=$i + 0.25) {
  3846.                 $this->addToList($this->pointD($this->z1Rect, $i, $this->zPos));
  3847.               }
  3848.  
  3849.               $this->drawPoints();
  3850.  
  3851.               for ($i = $tmpEndAng; $i >= 180; $i=$i - 0.25) {
  3852.                 $this->addToList($this->pointD($this->z1Rect, $i, $this->zPos));
  3853.               }
  3854.  
  3855.               if ($this->hasBevel) {
  3856.                 for ($i = 180; $i <= $tmpEndAng; $i=$i + 0.25) {
  3857.                   $this->addToList($this->pointD($this->z1BevelRect, $i, $this->zPos));
  3858.                 }
  3859.               }
  3860.               else {
  3861.                 for ($i = 180; $i <= $tmpEndAng; $i=$i + 0.25) {
  3862.                   $this->addToList($this->pointD($this->z0Rect, $i, $this->zPos));
  3863.                 }
  3864.               }
  3865.  
  3866.               $this->drawPoints();
  3867.  
  3868.               if ($tmpStartAng > 0) {
  3869.                 for ($i = 360; $i >= $tmpStartAng; $i=$i - 0.25) {
  3870.                   $this->addToList($this->pointD($this->z1Rect, $i, $this->zPos));
  3871.                 }
  3872.  
  3873.                 if ($this->hasBevel) {
  3874.                   for ($i = $tmpStartAng; $i <= 360; $i=$i + 0.25) {
  3875.                     $this->addToList($this->pointD($this->z1BevelRect, $i, $this->zPos));
  3876.                   }
  3877.                 }
  3878.                 else {
  3879.                   for ($i = $tmpStartAng; $i <= 360; $i=$i + 0.25) {
  3880.                     $this->addToList($this->pointD($this->z0Rect, $i, $this->zPos));
  3881.                   }
  3882.                 }
  3883.  
  3884.                 $this->drawPoints();
  3885.               }
  3886.               $this->drawBevel($tmpStartAng, $tmpEndAng, true);
  3887.             }
  3888.             else {
  3889.               if ($tmpEndAng < $tmpStartAng) {
  3890.                 $tmpEndAng += 360;
  3891.               }
  3892.  
  3893.               if ($this->hasBevel) {
  3894.                 for ($i = $tmpStartAng; $i <= $tmpEndAng; $i=$i + 0.25) {
  3895.                   $this->addToList($this->pointD($this->z1BevelRect, $i, $this->zPos));
  3896.                 }
  3897.               }
  3898.               else {
  3899.                 for ($i = $tmpStartAng; $i <= $tmpEndAng; $i=$i + 0.25) {
  3900.                   $this->addToList($this->pointD($this->z0Rect, $i, $this->zPos));
  3901.                 }
  3902.               }
  3903.  
  3904.               for ($i = $tmpEndAng; $i >= $tmpStartAng; $i=$i - 0.25) {
  3905.                 $this->addToList($this->pointD($this->z1Rect, $i, $this->zPos));
  3906.               }
  3907.  
  3908.               $this->drawPoints();
  3909.               $this->drawBevel($tmpStartAng, $tmpEndAng);
  3910.             }
  3911.           }
  3912.         }
  3913.  
  3914.         private function drawLeft()
  3915.         {
  3916.           if ($this->sweepAngle < 360 && ($this->drawEntirePie || $this->iDrawSides))
  3917.           {
  3918.             $this->ilist=Array();
  3919. //            $this->ilist[0]=new PointDouble();
  3920.  
  3921.             if ($this->isDonut)
  3922.             {
  3923.               if ($this->hasBevel)
  3924.               {
  3925.                 $this->addToList($this->endD0);
  3926.                 $this->addToList($this->endB0);
  3927.                 $this->addToList($this->endB1);
  3928.                 $this->addToList($this->end1);
  3929.                 $this->addToList($this->endD1);
  3930.                 $this->drawPoints();
  3931.               }
  3932.               else
  3933.               {
  3934.                 $this->g->iPointDoubles[0] = $this->endD0;
  3935.                 $this->g->iPointDoubles[1] = $this->end0;
  3936.                 $this->g->iPointDoubles[2] = $this->end1;
  3937.                 $this->g->iPointDoubles[3] = $this->endD1;
  3938.                 $this->g->polygonFourDouble();
  3939.               }
  3940.             }
  3941.             else
  3942.             {
  3943.               if ($this->hasBevel)
  3944.               {
  3945.                 $this->addToList($this->middle0);
  3946.                 $this->addToList($this->endB0);
  3947.                 $this->addToList($this->endB1);
  3948.                 $this->addToList($this->end1);
  3949.                 $this->addToList($this->middle1);
  3950.                 $this->drawPoints();
  3951.               }
  3952.               else
  3953.               {
  3954.                 $this->g->iPointDoubles[0] = $this->middle0;
  3955.                 $this->g->iPointDoubles[1] = $this->end0;
  3956.                 $this->g->iPointDoubles[2] = $this->end1;
  3957.                 $this->g->iPointDoubles[3] = $this->middle1;
  3958.                 $this->g->polygonFourDouble();
  3959.               }
  3960.             }
  3961.           }
  3962.         }
  3963.  
  3964.         private function drawLighting($edgeStyle, $last)
  3965.         {
  3966.           if ($this->hasBevel) {
  3967.             if ($this->gradientBrush == null) {
  3968.               $this->gradientBrush = new ChartBrush($this->g->getChart());
  3969.             }
  3970.             $oldPenVisible = $this->g->getPen()->getVisible();
  3971.             $this->g->getPen()->setVisible(false);
  3972.             $this->g->setBrush($this->gradientBrush);
  3973.  
  3974.             //if (last)
  3975.             //  doTopGradient(zPos);
  3976.             //else
  3977.             {
  3978.               switch ($edgeStyle)
  3979.               {
  3980.                 case 0:
  3981.                   $this->doFlatGradient($this->zPos);
  3982.                   break;
  3983.                 case 1:
  3984.                   $this->doCurvedGradient($this->zPos);
  3985.                   break;
  3986.               }
  3987.             }
  3988.  
  3989.             $this->g->getPen()->setVisible($oldPenVisible);
  3990.           }
  3991.         }
  3992.  
  3993.         private function drawRight()
  3994.         {
  3995.           if ($this->sweepAngle < 360 && ($this->drawEntirePie || $this->iDrawSides))
  3996.           {
  3997.             $this->ilist = Array();
  3998. //            $this->ilist[0]= new PointDouble();
  3999.  
  4000.             if ($this->isDonut)
  4001.             {
  4002.               if ($this->hasBevel)
  4003.               {
  4004.                 $this->addToList($this->startD0);
  4005.                 $this->addToList($this->startB0);
  4006.                 $this->addToList($this->startB1);
  4007.                 $this->addToList($this->start1);
  4008.                 $this->addToList($this->startD1);
  4009.                 $this->drawPoints();
  4010.               }
  4011.               else
  4012.               {
  4013.                 $this->g->iPointDoubles[0] = $this->startD0;
  4014.                 $this->g->iPointDoubles[1] = $this->start0;
  4015.                 $this->g->iPointDoubles[2] = $this->start1;
  4016.                 $this->g->iPointDoubles[3] = $this->startD1;
  4017.                 $this->g->polygonFourDouble();
  4018.               }
  4019.             }
  4020.             else
  4021.             {
  4022.               if ($this->hasBevel)
  4023.               {
  4024.                 $this->addToList($this->middle0);
  4025.                 $this->addToList($this->startB0);
  4026.                 $this->addToList($this->startB1);
  4027.                 $this->addToList($this->start1);
  4028.                 $this->addToList($this->middle1);
  4029.                 $this->drawPoints();
  4030.               }
  4031.               else
  4032.               {
  4033.                 $this->g->iPointDoubles[0] = $this->middle0;
  4034.                 $this->g->iPointDoubles[1] = $this->start0;
  4035.                 $this->g->iPointDoubles[2] = $this->start1;
  4036.                 $this->g->iPointDoubles[3] = $this->middle1;
  4037.                 $this->g->polygonFourDouble();
  4038.               }
  4039.             }
  4040.           }
  4041.         }
  4042.  
  4043.         private function drawBevel($startAng, $endAng, $split=false)
  4044.         {
  4045.           if ($this->hasBevel)
  4046.           {
  4047.             $tmpStartAng = $startAng;
  4048.             $tmpEndAng = $endAng;
  4049.  
  4050.             if ($split)
  4051.             {
  4052.               $oldPenVisible = $this->g->getPen()->getVisible();
  4053.               $this->g->getPen()->setVisible(false);
  4054.               for ($i = 180; $i >= 0; $i=$i - 0.25) {
  4055.                 $this->addToList($this->pointD($this->z0BevelRect, $i, $this->zPos));
  4056.               }
  4057.  
  4058.               for ($i = 0; $i <= 180; $i=$i + 0.25) {
  4059.                 $this->addToList($this->pointD($this->z1BevelRect, $i, $this->zPos));
  4060.               }
  4061.  
  4062.               $this->drawPoints();
  4063.  
  4064.               for ($i = $tmpEndAng; $i >= 180; $i=$i - 0.25) {
  4065.                 $this->addToList($this->pointD($this->z1BevelRect, $i, $this->zPos));
  4066.               }
  4067.  
  4068.               for ($i = 180; $i <= $tmpEndAng; $i=$i + 0.25) {
  4069.                 $this->addToList($this->pointD($this->z0BevelRect, $i, $this->zPos));
  4070.               }
  4071.  
  4072.               $this->drawPoints();
  4073.  
  4074.               if ($tmpStartAng > 0) {
  4075.                 for ($i = 360; $i >= $tmpStartAng; $i=$i - 0.25) {
  4076.                   $this->addToList($this->pointD($this->z1BevelRect, $i, $this->zPos));
  4077.                 }
  4078.  
  4079.                 for ($i = $tmpStartAng; $i <= 360; $i=$i + 0.25) {
  4080.                   $this->addToList($this->pointD($this->z0BevelRect, $i, $this->zPos));
  4081.                 }
  4082.  
  4083.                 $this->drawPoints();
  4084.               }
  4085.  
  4086.               $this->g->getPen()->setVisible($this->oldPenVisible);
  4087.             }
  4088.             else
  4089.             {
  4090.               if ($tmpEndAng < $tmpStartAng) {
  4091.                 $tmpEndAng += 360;
  4092.               }
  4093.  
  4094.               for ($i = $tmpStartAng; $i <= $tmpEndAng; $i=$i + 0.25) {
  4095.                 $this->addToList($this->pointD($this->z0BevelRect, $i, $this->zPos));
  4096.               }
  4097.               for ($i = $tmpEndAng; $i >= $tmpStartAng; $i=$i - 0.25) {
  4098.                 $this->addToList($this->pointD($this->z1BevelRect, $i, $this->zPos));
  4099.               }
  4100.             }
  4101.             $this->drawPoints();
  4102.           }
  4103.         }
  4104.  
  4105.         private function drawTop($startAng, $endAng)
  4106.         {
  4107.           $this->ilist=Array();
  4108. //          $this->ilist[0]=new PointDouble();
  4109.  
  4110.           if ($this->sweepAngle < 360 && !$this->isDonut)
  4111.           {
  4112.             $this->addToList($this->middle0);
  4113.           }
  4114.           if ($this->hasBevel)
  4115.           {
  4116.             for ($i = $startAng; $i <= $endAng; $i=$i + 0.25)
  4117.             {
  4118.               $this->addToList($this->pointD($this->z0BevelRect, $i, $this->zPos));
  4119.             }
  4120.           }
  4121.           else
  4122.           {
  4123.             for ($i = $startAng; $i <= $endAng; $i=$i + 0.25)
  4124.             {
  4125.               $this->addToList($this->pointD($this->z0Rect, $i, $this->zPos));
  4126.             }
  4127.           }
  4128.           if ($this->isDonut)
  4129.           {
  4130.             for ($i = $endAng; $i >= $startAng; $i=$i - 0.25)
  4131.             {
  4132.               $this->addToList($this->pointD($this->z0DonutRect, $i, $this->zPos));
  4133.             }
  4134.           }
  4135.           if ($this->sweepAngle < 360 && !$this->isDonut)
  4136.           {
  4137.             $this->addToList($this->middle0);
  4138.           }
  4139.           $this->drawPoints();
  4140.         }
  4141.  
  4142.         private function drawBottom($startAng, $endAng)
  4143.         {
  4144.           if ($this->drawEntirePie)
  4145.           {
  4146.             if ($this->sweepAngle < 360 && !$this->isDonut)
  4147.             {
  4148.               $this->addToList($this->middle1);
  4149.             }
  4150.             for ($i = $startAng; $i <= $endAng; $i=$i + 0.25)
  4151.             {
  4152.               $this->addToList($this->pointD($this->z1Rect, $i, $this->zPos));
  4153.             }
  4154.             if ($this->isDonut)
  4155.             {
  4156.               for ($i = $endAng; $i >= $startAng; $i=$i - 0.25)
  4157.               {
  4158.                 $this->addToList($this->pointD($this->z1DonutRect, $i, $this->zPos));
  4159.               }
  4160.             }
  4161.             if ($this->sweepAngle < 360 && !$this->isDonut)
  4162.             {
  4163.               $this->addToList($this->middle1);
  4164.             }
  4165.  
  4166.             $this->drawPoints();
  4167.  
  4168.           }
  4169.         }
  4170.  
  4171.         private function drawPoints()
  4172.         {
  4173.           if (sizeof($this->ilist) > 0) {
  4174.             if (sizeof($this->ilist)>3) {
  4175.               $this->g->polygon($this->ilist);
  4176.             }
  4177.             $this->ilist=Array();
  4178.           }
  4179.         }
  4180.  
  4181.         private function doTopGradient($zDepth)
  4182.         {
  4183.           $this->g->getPen()->setVisible(false);
  4184.           $this->ilist=Array();
  4185.           for ($i = 0; $i <= 360; $i=$i + 0.25)
  4186.           {
  4187.             $this->addToList($this->pointD($this->z0BevelRect, $i, $zDepth));
  4188.           }
  4189.  
  4190.           $shape = $this->ilist;
  4191.  
  4192.           $this->gradientBrush->getGradient()->setVisible(true);
  4193.           $this->gradientBrush->getGradient()->setStartColor(new Color(255,255,255,140));
  4194.           $this->gradientBrush->getGradient()->setEndColor(new Color(255,255,0));          
  4195.                     
  4196.           $this->gradientBrush->getGradient()->setDirection(GradientDirection::$CIRCLE);
  4197.           /* TODO Check which better
  4198.           $this->gradientBrush->getGradient()->setDirection(GradientDirection::$RADIAL);
  4199.           $this->gradientBrush->getGradient()->setRadialX((int)-MathUtils::round($this->z0BevelRect->getWidth() / 4));
  4200.           $this->gradientBrush->getGradient()->setRadialY((int)-MathUtils::round($this->z0BevelRect->getHeight() / 3 ));
  4201.           $this->gradientBrush->getGradient()->setCustomTargetPolygon(PointDouble::roundPointArray($shape));
  4202.           */
  4203.           
  4204.           $this->ilist=Array();
  4205.  
  4206.           if (!$this->isDonut) {
  4207.             $this->addToList($this->middle0);
  4208.           }
  4209.  
  4210.           for ($i = $this->iStartAngle; $i <= $this->iEndAngle; $i=$i + 0.25) {
  4211.             $this->addToList($this->pointD($this->z0BevelRect, $i, $zDepth));
  4212.           }
  4213.  
  4214.           if ($this->isDonut) {
  4215.             for ($i = $this->iEndAngle; $i >= $this->iStartAngle; $i=$i - 0.25) {
  4216.               $this->addToList($this->pointD($this->z0DonutRect, $i, $zDepth));
  4217.             }
  4218.           }
  4219.  
  4220.           $this->g->setBrush($this->gradientBrush);
  4221.           if (sizeof($this->ilist)>3) {
  4222.               $this->g->polygon($this->ilist);
  4223.           }
  4224.         }
  4225.  
  4226.         private function doFlatGradient($zDepth)
  4227.         {
  4228.           $this->doTopGradient($zDepth);
  4229.  
  4230.           if (($this->iStartAngle <= 295 && $this->iEndAngle >= 335)
  4231.             || ($this->iStartAngle >= 295 && $this->iStartAngle <= 335)
  4232.             || ($this->iEndAngle >= 295 && $this->iEndAngle <= 335))
  4233.           {
  4234.  
  4235.           $this->ilist=Array();
  4236. //          $this->ilist[0]=new PointDouble();
  4237.  
  4238.             for ($i = 295; $i <= 335; $i=$i + 0.25) {
  4239.               $this->addToList($this->pointD($this->z1BevelRect, $i, $zDepth));
  4240.             }
  4241.  
  4242.             for ($i = 335; $i >= 295; $i=$i - 0.25) {
  4243.               $this->addToList($this->pointD($this->z0BevelRect, $i, $zDepth));
  4244.             }
  4245.  
  4246.             $shape = $this->ilist;
  4247.             $this->gradientBrush->getGradient()->setVisible(true);
  4248.             $this->gradientBrush->getGradient()->setStartColor(new Color(255,255,255,0));
  4249.  
  4250.             // TODO $this->gradientBrush->getGradient()->setMiddleColor(Color::fromArgb(160, 255, 255, 255));
  4251.             // TODO $this->gradientBrush->getGradient()->setUseMiddle(true);
  4252.             $this->gradientBrush->getGradient()->setEndColor(new Color(255,255,255,0));
  4253.  
  4254.             // TODO $this->gradientBrush->getGradient()->setDirection(GradientDirection::$FORWARDDIAGONAL);
  4255.             // Remove following line
  4256.             $this->gradientBrush->getGradient()->setDirection(GradientDirection::$VERTICAL);
  4257.             //gradientBrush.getGradient().setAngle(0);
  4258.             $this->gradientBrush->getGradient()->setCustomTargetPolygon(PointDouble::roundPointArray($shape));
  4259.  
  4260.             $this->ilist=Array();
  4261.  
  4262.             if ($this->iStartAngle <= 295 && $this->iEndAngle >= 335) {
  4263.               $start = 295;
  4264.               $end = 335;
  4265.             }
  4266.             elseif ($this->iStartAngle >= 295 && $this->iStartAngle <= 335) {
  4267.               $start = $this->iStartAngle;
  4268.               $end = 335;
  4269.             }
  4270.             elseif ($this->iEndAngle >= 295 && $this->iEndAngle <= 335) {
  4271.               $start = 295;
  4272.               $end = $this->iEndAngle;
  4273.             }
  4274.             else {
  4275.               $start = 0;
  4276.               $end = 0;
  4277.             }
  4278.  
  4279.             for ($i = $start; $i <= $end; $i=$i + 0.25) {
  4280.               $this->addToList($this->pointD($this->z1BevelRect, $i, $zDepth));
  4281.             }
  4282.  
  4283.             for ($i = $end; $i >= $start; $i=$i - 0.25) {
  4284.               $this->addToList($this->pointD($this->z0BevelRect, $i, $zDepth));
  4285.             }
  4286.  
  4287.             $this->g->setBrush($this->gradientBrush);
  4288.             if (sizeof($this->ilist)>3) {
  4289.               $this->g->polygon($this->ilist);
  4290.             }
  4291.           }
  4292.         }
  4293.  
  4294.         private function doCurvedGradient($zDepth)
  4295.         {
  4296.           $this->doTopGradient($zDepth);
  4297.           /*TODO
  4298.           if ((iStartAngle <= 295 && iEndAngle >= 335)
  4299.             || (iStartAngle >= 295 && iStartAngle <= 335)
  4300.             || (iEndAngle >= 295 && iEndAngle <= 335))
  4301.           */
  4302.           {
  4303.           $this->ilist=Array();
  4304.  
  4305.             for ($i = 295; $i <= 335; $i=$i + 0.25) {
  4306.               $this->addToList($this->pointD($this->z1BevelRect, $i, $zDepth));
  4307.             }
  4308.  
  4309.             for ($i = 335; $i >= 295; $i=$i - 0.25) {
  4310.               $this->addToList($this->pointD($this->z0BevelRect, $i, $zDepth));
  4311.             }
  4312.  
  4313.             $shape = $this->ilist;
  4314.             // TODO $this->gradientBrush->getGradient()->setRadialX(0);
  4315.             // TODO $this->gradientBrush->getGradient()->setRadialY(0);
  4316.  
  4317.             $this->gradientBrush->getGradient()->setVisible(true);
  4318.             // TODO Remove the following 2 lines
  4319.             $this->gradientBrush->getGradient()->setStartColor(new Color(255,255,255,255));
  4320.             $this->gradientBrush->getGradient()->setEndColor(new Color(255,255,255,0));
  4321.  
  4322.             // TODO $this->gradientBrush->getGradient()->setDirection(GradientDirection::$RADIAL);
  4323.             // TODO $this->gradientBrush->getGradient()->setAngle(135);
  4324.             $this->gradientBrush->getGradient()->setDirection('vertical');  // ellipse
  4325.             $this->gradientBrush->getGradient()->setCustomTargetPolygon(PointDouble::roundPointArray($shape));
  4326.  
  4327.             $this->ilist = Array();
  4328.             if ($this->iStartAngle <= 295 && $this->iEndAngle >= 335) {
  4329.               $start = 295;
  4330.               $end = 335;
  4331.             }
  4332.             elseif ($this->iStartAngle >= 295 && $this->iStartAngle <= 335) {
  4333.               $start = $this->iStartAngle;
  4334.               $end = 335;
  4335.             }
  4336.             elseif ($this->iEndAngle >= 295 && $this->iEndAngle <= 335) {
  4337.               $start = 295;
  4338.               $end = $this->iEndAngle;
  4339.             }
  4340.             else {
  4341.               $start = 0;
  4342.               $end = 0;
  4343.             }
  4344.  
  4345.             for ($i = $start; $i <= $end; $i=$i + 0.25) {
  4346.               $this->addToList($this->pointD($this->z1BevelRect, $i, $zDepth));
  4347.             }
  4348.  
  4349.             for ($i = $end; $i >= $start; $i=$i - 0.25) {
  4350.               $this->addToList($this->pointD($this->z0BevelRect, $i, $zDepth));
  4351.             }
  4352.  
  4353.             $this->g->setBrush($this->gradientBrush);
  4354.             if (sizeof($this->ilist)>3) {
  4355.               $this->g->polygon($this->ilist);
  4356.             }
  4357.           }
  4358.         }
  4359.     }
  4360. ?>

Documentation generated on Wed, 16 Jun 2010 12:05:59 +0200 by phpDocumentor 1.4.1